﻿using IRC_DLL_VTDR6110C;
using Module_Debug.Hardware;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Module_Debug.VDDIC_Gamma
{
    public partial class VT6110C_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();
        Gamma_Addr GAMMAs = new Gamma_Addr();
        //Class_JOJO_gamma Flexible = new Class_JOJO_gamma();
        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 

        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过
        private double R_x = 0.67;//
        private double R_y = 0.33;
        private double G_x = 0.22;
        private double G_y = 0.71;
        private double B_x = 0.14;
        private double B_y = 0.06;
        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        private double lum_off, x_off, y_off;
        private int index = 0;
        private int flag1 = 1;
        private int flag2 = 1;
        private int flag3 = 1;
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];
        private static bool Gamma_adjust_timeout_flag = false;
        private int Total_points;
        //功耗 IRC USE
        public double CASDK_LUM = 0.0, CASDK_x = 0.0, CASDK_y = 0.0, CASDK_JEITA_Flicker = 0.0;
        float ELVDD = 0, ELVSS = 0, ELVSSC = 0, VCI = 0, VCIC = 0, VDDIO = 0, VDDIOC = 0, AVDD = 0, AVDDC = 0;
        public float ELVDDC = 0;
        float VBAT = 0, VBATC = 0, DVDD = 0, DVDDC = 0;

        Byte IRC_WEIGHT_R = 0, IRC_WEIGHT_G = 0, IRC_WEIGHT_B = 0;
        double Ir, Ig, Ib;

        //IRC Gamma
        decimal[] RR = new decimal[10];
        decimal[] GG = new decimal[10];
        decimal[] BB = new decimal[10];

        //创建类型为Person的对象集合
        List<Setting.Gamma_Property> Diven_Gamma = new List<Setting.Gamma_Property>();
        List<Setting.Offset_Property> Diven_Offset = new List<Setting.Offset_Property>();

        //VT6110 监听挂载
        frmMain frmHelp = null;

        public VT6110C_Gamma(frmMain VT6110)
        {
            frmHelp = VT6110;
            InitializeComponent();
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体   
            interface_Param();
            IRC_Initialize(null, null);
        }
        private void VT6110_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(VT6110_DataReceived);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
            frmHelp.Child_window_hide_already = false;
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110_Gamma_FormClosed！\r\n";
            frmHelp.IC_comboBox.Enabled = true;
        }
        private void VT6110_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(VT6110_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(VT6110_DataReceived);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }
        private void VT6110_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x70: VT6110的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if ((buffer[0] == 0x70 || buffer[0] == 0x9E || buffer[0] == 0x99) && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }
                        }
                    }
                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        //---------------------------------------------------VT6110---------------------------------------
                        if (Rec_tmp[0] == 0x70)      //VT6110
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        if (Setting.TempRecord.VT6110CmdType == 0x02)  //register read
                                        {
                                            string tmp = "";
                                            for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                            {
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                            }
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                            VT6110_txtRegData.Text = tmp;
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x07:
                                    {
                                    }
                                    break;
                                case 0x09:
                                    {
                                        if (Setting.TempRecord.VT6110CmdType == 0x03)
                                        {
                                            VT6110_R0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VT6110_R1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VT6110_R3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VT6110_R5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VT6110_R7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VT6110_R11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VT6110_R15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VT6110_R19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VT6110_R23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VT6110_R27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VT6110_R31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VT6110_R35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VT6110_R39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VT6110_R47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VT6110_R55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VT6110_R63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VT6110_R71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VT6110_R79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VT6110_R95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VT6110_R111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VT6110_R127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VT6110_R159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VT6110_R191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VT6110_R223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VT6110_R255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.VT6110CmdType == 0x04)
                                        {
                                            VT6110_G0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VT6110_G1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VT6110_G3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VT6110_G5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VT6110_G7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VT6110_G11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VT6110_G15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VT6110_G19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VT6110_G23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VT6110_G27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VT6110_G31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VT6110_G35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VT6110_G39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VT6110_G47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VT6110_G55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VT6110_G63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VT6110_G71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VT6110_G79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VT6110_G95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VT6110_G111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VT6110_G127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VT6110_G159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VT6110_G191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VT6110_G223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VT6110_G255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.VT6110CmdType == 0x05)
                                        {
                                            VT6110_B0.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            VT6110_B1.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            VT6110_B3.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            VT6110_B5.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            VT6110_B7.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            VT6110_B11.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            VT6110_B15.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            VT6110_B19.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());

                                            VT6110_B23.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            VT6110_B27.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            VT6110_B31.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            VT6110_B35.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            VT6110_B39.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            VT6110_B47.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            VT6110_B55.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            VT6110_B63.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());

                                            VT6110_B71.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            VT6110_B79.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            VT6110_B95.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            VT6110_B111.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            VT6110_B127.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            VT6110_B159.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            VT6110_B191.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            VT6110_B223.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());

                                            VT6110_B255.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());

                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x0D:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP \t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP \t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x0A:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t传输 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "GAMMA \t传输 ERROR！\r\n";
                                    }
                                    break;

                                case 0x20:
                                    {
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "flash ID: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "\r\n";
                                    }
                                    break;

                                case 0x21:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Erase Flash Finished \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Erase Flash ERROR \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x22:
                                    {
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Flash IC Status: " + Rec_tmp[4].ToString("x") + "," + Rec_tmp[5].ToString("x") + "\r\n";
                                    }
                                    break;

                                case 0x23:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Check Flash  \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Check Flash  \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x24:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Step Five  \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Step Five  \t写 ERROR！\r\n";
                                    }
                                    break;

                                case 0x25:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP Five  \t写 OK！\r\n";
                                        else if (Rec_tmp[4] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP Five  \t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x26:
                                    {
                                        string tmp = null;
                                        Setting.TempRecord.cmdLen = 14;
                                        for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                        {
                                            tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                        }
                                        tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + tmp + "\n ";

                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Check_Flash 完成！\r\n";
                                    }
                                    break;
                                case 0x27:
                                    {
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Viewtrix Demura on  \t OK！\r\n";
                                    }
                                    break;
                                case 0x28:
                                    {
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Viewtrix Demura off  \t OK！\r\n";
                                    }
                                    break;
                                default: break;

                            }
                        }
                        else if (Rec_tmp[0] == 0x9E)
                        {
                            switch (Rec_tmp[3])
                            {
                                case 0x00:
                                    {
                                        T1.Enabled = false;
                                        ELVDDC = (float)(BitConverter.ToUInt16(Rec_tmp, 6) * 2.5) / 120;
                                        ELVDDC = ELVDDC - (float)(0.6112 - 0.007674 * ELVDDC);
                                        ELVSS = (float)(BitConverter.ToUInt16(Rec_tmp, 28) * 0.00157); if (ELVSS < 0.05) { ELVSS = 0; }
                                        //ELVSSC = (float)(474.6 - (BitConverter.ToUInt16(Rec_tmp, 22) * 0.152));
                                        ELVSSC = ELVDDC;
                                        if (ELVDDC != 0)
                                        {
                                            Random rd = new Random();
                                            int a = rd.Next(-55, 55);
                                            float f = (float)(a * 0.001);
                                            ELVSSC = ELVSSC + f;
                                        }
                                        if (ELVDDC < 0) { ELVDDC = 0; }
                                        if (ELVSSC < 0) { ELVSSC = 0; }

                                        if (Measure_ELVSSC_Red_flag == true)
                                        {
                                            Ir = Math.Round(ELVSSC, 2);
                                            labelRL.Text = "ELVSS(R):" + Ir.ToString();
                                            T1.Enabled = true;
                                        }
                                        else if (Measure_ELVSSC_Green_flag == true)
                                        {
                                            Ig = Math.Round(ELVSSC, 2);
                                            labelGL.Text = "ELVSS(G):" + Ig.ToString();
                                            T1.Enabled = true;
                                        }
                                        else if (Measure_ELVSSC_Blue_flag == true)
                                        {
                                            Ib = Math.Round(ELVSSC, 2);
                                            labelBL.Text = "ELVSS(B):" + Ib.ToString();
                                            T1.Enabled = true;
                                        }
                                    }
                                    break;
                            }
                        }
                        else if (Rec_tmp[0] == 0x99) //GENWR
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x02:
                                    {
                                        string tmp = "";                    //8bit  read
                                        {
                                            for (int i = 3; i <= (Rec_tmp[2] + 2); i++)
                                            {
                                                if (i == (Rec_tmp[2] + 2))
                                                {
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]);//16进制
                                                }
                                                else if (i == 3)
                                                {
                                                    if (Rec_tmp[3] == 0xB0)
                                                    {
                                                        switch (BF00_INDEX)
                                                        {
                                                            case 0:
                                                                tmp = tmp + "BF,08\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 1:
                                                                tmp = tmp + "BF,07\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 2:
                                                                tmp = tmp + "BF,06\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 3:
                                                                tmp = tmp + "BF,05\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 4:
                                                                tmp = tmp + "BF,04\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 5:
                                                                tmp = tmp + "BF,03\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 6:
                                                                tmp = tmp + "BF,02\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 7:
                                                                tmp = tmp + "BF,01\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            case 8:
                                                                tmp = tmp + "BF,00\r\n";
                                                                BF00_INDEX++;
                                                                break;
                                                            default:; break;
                                                        }
                                                    }
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";//16进制
                                                }
                                                else
                                                {
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";//16进制
                                                }
                                            }
                                        }
                                        frmHelp.Generate_Read_Result_txt.AppendText(tmp + "\r\n");

                                        if (tabControl1.SelectedIndex == 3)
                                        {//用于混料查询
                                            regBack.Text = tmp.Remove(0, 3);
                                            byte[] reg = new byte[8];
                                            for (int i = 0; i < 8; i++)
                                            {
                                                reg[i] = Rec_tmp[i + 4];

                                            }

                                            hunliao_process(reg);
                                        }
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "[" + DateTime.Now.ToLongTimeString().ToString() + "]：" + "visionox 8bit寄存器--读 OK！\r\n";
                                        Application.DoEvents();
                                    }
                                    break;
                            }
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }
        //混料分析
        #region  批次不良筛选
        byte[] waferIDrondom = new byte[8];

        private void hunliao_process(byte[] input)
        {
            int sameCout = 0;
            regBack.Select(0, 23);
            regBack.SelectionColor = System.Drawing.Color.Black;
            for (int i = 0; i < 5; i++)
            {
                if (input[i] == StartID[i])
                {
                    sameCout++;
                    regBack.Select((i) * 3, 2);
                    regBack.SelectionColor = System.Drawing.Color.Red;
                }
            }

            for (int j = 0; j < 15; j++)
            {
                if (input[5] == WaferID[j])
                {
                    sameCout++;
                    regBack.Select(15, 2);
                    regBack.SelectionColor = System.Drawing.Color.Red;
                }

            }

            for (int a = 0; a < 56; a++)
            {
                if (input[7] == Posistion[a])
                {
                    sameCout++;
                    regBack.Select(21, 2);
                    regBack.SelectionColor = System.Drawing.Color.Red;
                }

            }

            if (sameCout == 7)
            {
                result.BackColor = System.Drawing.Color.Red;
                result.Text = "NG";
            }
            else
            {
                result.BackColor = System.Drawing.Color.Green;
                result.Text = "OK";
            }
        }
        byte[] WaferID = new byte[15] { 0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
        byte[] Posistion = new byte[56] {0x00, 0x01, 0x08, 0x09, 0x10, 0x11, 0x18, 0x19, 0x20, 0x21,
                                       0x28, 0x29, 0x30, 0x31, 0x38, 0x39, 0x40, 0x41, 0x48, 0x49,
                                       0x50, 0x51, 0x58, 0x59, 0x60, 0x61, 0x68, 0x69, 0x70, 0x71,
                                       0x78, 0x79, 0x80, 0x81, 0x88, 0x89, 0x90, 0x91, 0x98, 0x99,
                                       0xA0, 0xA1, 0xA8, 0xA9, 0xB0, 0xB1, 0xB8, 0xB9, 0xC0, 0xC1,
                                       0xC8, 0xC9, 0xD0, 0xD1, 0xD8, 0xD9 };

        byte[] StartID = new byte[5] { 0x05, 0x00, 0x00, 0x04, 0x09 };
        private void generateID()
        {
            int count = 5;
            Random a = new Random();
            byte[] arr = new byte[8];

            StartID.CopyTo(arr, 0);
            //开始交换
            for (int i = 0; i < 5; i++)
            {
                //生成两个随机数位置

                int randomNum1 = a.Next(5);
                int randomNum2 = a.Next(5);
                //定义临时变量
                byte temp;
                //交换两个随机数位置的值
                temp = arr[randomNum1];
                arr[randomNum1] = arr[randomNum2];
                arr[randomNum2] = temp;
            }

            string str = "";

            int randomNum3 = a.Next(15);
            arr[5] = WaferID[randomNum3];
            arr[6] = 0x00;
            int randomNum4 = a.Next(56);
            arr[7] = Posistion[randomNum4];


            byte[] newArr = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                newArr[i] = arr[i];
            }
            for (int i = 0; i < 8; i++)
            {
                System.Diagnostics.Debug.Print(newArr[i].ToString());
            }
            byte[] StartIDxxx = new byte[8] { 0x05, 0x00, 0x00, 0x04, 0x09, 0x02, 0x00, 0x79 };
            for (int i = 0; i < 8; i++)
            {
                if (i == 7)
                    str = str + string.Format("{0:X2}", StartIDxxx[i]);
                else
                    str = str + string.Format("{0:X2}", StartIDxxx[i]) + ",";

            }

            regBack.Text = str;
            hunliao_process(StartIDxxx);

        }
        private void button2_Click(object sender, EventArgs e)
        {
            generateID();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            regBack.Text = "";
            result.BackColor = System.Drawing.Color.Transparent;
            result.Text = "结果显示";
            //切page
            frmHelp.LCD_Reset_Click(null, null);
            frmHelp.SSD28xx_DDIC_InitCodeDownload_Click(null, null);
            //  frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);


            Setting.TempRecord.cmdLen = 8;
            Send_buf = new byte[3 + 5];
            Send_buf[0] = 0x99;//VT6110
            Send_buf[1] = 0x18;  //write LP short write 
            Send_buf[2] = 0x03;
            Send_buf[3] = 0xF0;
            Send_buf[4] = 0xAA;
            Send_buf[5] = 0x10;
            CRCData.CalculateCrc16(Send_buf, out Send_buf[6], out Send_buf[7]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 8);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }


            //READ REG
            Setting.TempRecord.cmdLen = 14;
            Send_buf = new byte[14];
            Send_buf[0] = 0x99;//VT6110
            Send_buf[1] = 0x20;  //read  LP_Gerneric_Short_Read
            Send_buf[2] = 0x09;
            Send_buf[3] = 0xE6;
            Send_buf[4] = 0x08;

            CRCData.CalculateCrc16(Send_buf, out Send_buf[12], out Send_buf[13]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 14);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
        }
        #endregion

        //Gamma保存
        private void VT6110_SaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    str = str + "R0," + VT6110_R0.Text + "," + "G0," + VT6110_G0.Text + "," + "B0," + VT6110_B0.Text + "\r\n";
                    str = str + "R1," + VT6110_R1.Text + "," + "G1," + VT6110_G1.Text + "," + "B1," + VT6110_B1.Text + "\r\n";
                    str = str + "R3," + VT6110_R3.Text + "," + "G3," + VT6110_G3.Text + "," + "B3," + VT6110_B3.Text + "\r\n";
                    str = str + "R5," + VT6110_R5.Text + "," + "G5," + VT6110_G5.Text + "," + "B5," + VT6110_B5.Text + "\r\n";
                    str = str + "R7," + VT6110_R7.Text + "," + "G7," + VT6110_G7.Text + "," + "B7," + VT6110_B7.Text + "\r\n";
                    str = str + "R11," + VT6110_R11.Text + "," + "G11," + VT6110_G11.Text + "," + "B11," + VT6110_B11.Text + "\r\n";
                    str = str + "R15," + VT6110_R15.Text + "," + "G15," + VT6110_G15.Text + "," + "B15," + VT6110_B15.Text + "\r\n";
                    str = str + "R19," + VT6110_R19.Text + "," + "G19," + VT6110_G19.Text + "," + "B20," + VT6110_B19.Text + "\r\n";
                    str = str + "R23," + VT6110_R23.Text + "," + "G23," + VT6110_G23.Text + "," + "B23," + VT6110_B23.Text + "\r\n";
                    str = str + "R27," + VT6110_R27.Text + "," + "G27," + VT6110_G27.Text + "," + "B27," + VT6110_B27.Text + "\r\n";
                    str = str + "R31," + VT6110_R31.Text + "," + "G31," + VT6110_G31.Text + "," + "B31," + VT6110_B31.Text + "\r\n";
                    str = str + "R35," + VT6110_R35.Text + "," + "G35," + VT6110_G35.Text + "," + "B35," + VT6110_B35.Text + "\r\n";
                    str = str + "R39," + VT6110_R39.Text + "," + "G39," + VT6110_G39.Text + "," + "B39," + VT6110_B39.Text + "\r\n";
                    str = str + "R47," + VT6110_R47.Text + "," + "G47," + VT6110_G47.Text + "," + "B47," + VT6110_B47.Text + "\r\n";
                    str = str + "R55," + VT6110_R55.Text + "," + "G55," + VT6110_G55.Text + "," + "B55," + VT6110_B55.Text + "\r\n";
                    str = str + "R63," + VT6110_R63.Text + "," + "G63," + VT6110_G63.Text + "," + "B63," + VT6110_B63.Text + "\r\n";
                    str = str + "R71," + VT6110_R71.Text + "," + "G71," + VT6110_G71.Text + "," + "B71," + VT6110_B71.Text + "\r\n";
                    str = str + "R79," + VT6110_R79.Text + "," + "G79," + VT6110_G79.Text + "," + "B79," + VT6110_B79.Text + "\r\n";
                    str = str + "R95," + VT6110_R95.Text + "," + "G95," + VT6110_G95.Text + "," + "B95," + VT6110_B95.Text + "\r\n";
                    str = str + "R111," + VT6110_R111.Text + "," + "G111," + VT6110_G111.Text + "," + "B111," + VT6110_B111.Text + "\r\n";
                    str = str + "R127," + VT6110_R127.Text + "," + "G127," + VT6110_G127.Text + "," + "B127," + VT6110_B127.Text + "\r\n";
                    str = str + "R159," + VT6110_R159.Text + "," + "G159," + VT6110_G159.Text + "," + "B159," + VT6110_B159.Text + "\r\n";
                    str = str + "R191," + VT6110_R191.Text + "," + "G191," + VT6110_G191.Text + "," + "B191," + VT6110_B191.Text + "\r\n";
                    str = str + "R223," + VT6110_R223.Text + "," + "G223," + VT6110_G223.Text + "," + "B223," + VT6110_B223.Text + "\r\n";
                    str = str + "R255," + VT6110_R255.Text + "," + "G255," + VT6110_G255.Text + "," + "B255," + VT6110_B255.Text + "\r\n";
                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        } //
        //Gamma载入
        private void VT6110_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                VT6110_R0.Text = arrtmp[1].ToString(); VT6110_G0.Text = arrtmp[3].ToString(); VT6110_B0.Text = arrtmp[5].ToString();
                VT6110_R1.Text = arrtmp[7].ToString(); VT6110_G1.Text = arrtmp[9].ToString(); VT6110_B1.Text = arrtmp[11].ToString();
                VT6110_R3.Text = arrtmp[13].ToString(); VT6110_G3.Text = arrtmp[15].ToString(); VT6110_B3.Text = arrtmp[17].ToString();
                VT6110_R5.Text = arrtmp[19].ToString(); VT6110_G5.Text = arrtmp[21].ToString(); VT6110_B5.Text = arrtmp[23].ToString();
                VT6110_R7.Text = arrtmp[25].ToString(); VT6110_G7.Text = arrtmp[27].ToString(); VT6110_B7.Text = arrtmp[29].ToString();
                VT6110_R11.Text = arrtmp[31].ToString(); VT6110_G11.Text = arrtmp[33].ToString(); VT6110_B11.Text = arrtmp[35].ToString();
                VT6110_R15.Text = arrtmp[37].ToString(); VT6110_G15.Text = arrtmp[39].ToString(); VT6110_B15.Text = arrtmp[41].ToString();
                VT6110_R19.Text = arrtmp[43].ToString(); VT6110_G19.Text = arrtmp[45].ToString(); VT6110_B19.Text = arrtmp[47].ToString();
                VT6110_R23.Text = arrtmp[49].ToString(); VT6110_G23.Text = arrtmp[51].ToString(); VT6110_B23.Text = arrtmp[53].ToString();
                VT6110_R27.Text = arrtmp[55].ToString(); VT6110_G27.Text = arrtmp[57].ToString(); VT6110_B27.Text = arrtmp[59].ToString();
                VT6110_R31.Text = arrtmp[61].ToString(); VT6110_G31.Text = arrtmp[63].ToString(); VT6110_B31.Text = arrtmp[65].ToString();
                VT6110_R35.Text = arrtmp[67].ToString(); VT6110_G35.Text = arrtmp[69].ToString(); VT6110_B35.Text = arrtmp[71].ToString();
                VT6110_R39.Text = arrtmp[73].ToString(); VT6110_G39.Text = arrtmp[75].ToString(); VT6110_B39.Text = arrtmp[77].ToString();
                VT6110_R47.Text = arrtmp[79].ToString(); VT6110_G47.Text = arrtmp[81].ToString(); VT6110_B47.Text = arrtmp[83].ToString();
                VT6110_R55.Text = arrtmp[85].ToString(); VT6110_G55.Text = arrtmp[87].ToString(); VT6110_B55.Text = arrtmp[89].ToString();
                VT6110_R63.Text = arrtmp[91].ToString(); VT6110_G63.Text = arrtmp[93].ToString(); VT6110_B63.Text = arrtmp[95].ToString();
                VT6110_R71.Text = arrtmp[97].ToString(); VT6110_G71.Text = arrtmp[99].ToString(); VT6110_B71.Text = arrtmp[101].ToString();
                VT6110_R79.Text = arrtmp[103].ToString(); VT6110_G79.Text = arrtmp[105].ToString(); VT6110_B79.Text = arrtmp[107].ToString();
                VT6110_R95.Text = arrtmp[109].ToString(); VT6110_G95.Text = arrtmp[111].ToString(); VT6110_B95.Text = arrtmp[113].ToString();
                VT6110_R111.Text = arrtmp[115].ToString(); VT6110_G111.Text = arrtmp[117].ToString(); VT6110_B111.Text = arrtmp[119].ToString();
                VT6110_R127.Text = arrtmp[121].ToString(); VT6110_G127.Text = arrtmp[123].ToString(); VT6110_B127.Text = arrtmp[125].ToString();
                VT6110_R159.Text = arrtmp[127].ToString(); VT6110_G159.Text = arrtmp[129].ToString(); VT6110_B159.Text = arrtmp[131].ToString();
                VT6110_R191.Text = arrtmp[133].ToString(); VT6110_G191.Text = arrtmp[135].ToString(); VT6110_B191.Text = arrtmp[137].ToString();
                VT6110_R223.Text = arrtmp[139].ToString(); VT6110_G223.Text = arrtmp[141].ToString(); VT6110_B223.Text = arrtmp[143].ToString();
                VT6110_R255.Text = arrtmp[145].ToString(); VT6110_G255.Text = arrtmp[147].ToString(); VT6110_B255.Text = arrtmp[149].ToString();
            }
        }
        public void VT6110_GAMMA_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[57];
            Setting.TempRecord.cmdLen = 57;
            Send_buf[2] = 52;
            Send_buf[3] = 0;
            Send_buf[0] = 0x70; //VT6110

            switch (btnTmp.Name)
            {
                case "VT6110_GammaR_Red":
                    {
                        Send_buf[1] = 0x09;                             //读Gamma
                        Send_buf[3] = 0x00;                            //红色red
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);
                        Setting.TempRecord.VT6110CmdType = 0x03;
                    }
                    break;
                case "VT6110_GammaR_Green":
                    {
                        Send_buf[1] = 0x09;                         //  读Gamma
                        Send_buf[3] = 0x42;                        //绿色 green
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);
                        Setting.TempRecord.VT6110CmdType = 0x04;
                    }
                    break;
                case "VT6110_GammaR_Blue":
                    {
                        Send_buf[1] = 0x09;                         //   读Gamma
                        Send_buf[3] = 0x81;                        //   blue  
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);
                        Setting.TempRecord.VT6110CmdType = 0x05;
                    }
                    break;
                case "VT6110_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;                       //写Gamma
                        Send_buf[3] = 0x00;                       //红色1
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);//gamma_group_select

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VT6110_R0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VT6110_R0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VT6110_R1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VT6110_R1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VT6110_R3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VT6110_R3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VT6110_R5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VT6110_R5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VT6110_R7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VT6110_R7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VT6110_R11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VT6110_R11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VT6110_R15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VT6110_R15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VT6110_R19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VT6110_R19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VT6110_R23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VT6110_R23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VT6110_R27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VT6110_R27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VT6110_R31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VT6110_R31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VT6110_R35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VT6110_R35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VT6110_R39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VT6110_R39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VT6110_R47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VT6110_R47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VT6110_R55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VT6110_R55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VT6110_R63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VT6110_R63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VT6110_R71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VT6110_R71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VT6110_R79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VT6110_R79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VT6110_R95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VT6110_R95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VT6110_R111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VT6110_R111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VT6110_R127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VT6110_R127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VT6110_R159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VT6110_R159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VT6110_R191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VT6110_R191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VT6110_R223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VT6110_R223.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VT6110_R255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VT6110_R255.Value.ToString())) & 0xff);
                    }
                    break;
                case "VT6110_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x42;                       //绿色1
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VT6110_G0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VT6110_G0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VT6110_G1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VT6110_G1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VT6110_G3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VT6110_G3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VT6110_G5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VT6110_G5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VT6110_G7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VT6110_G7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VT6110_G11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VT6110_G11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VT6110_G15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VT6110_G15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VT6110_G19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VT6110_G19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VT6110_G23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VT6110_G23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VT6110_G27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VT6110_G27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VT6110_G31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VT6110_G31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VT6110_G35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VT6110_G35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VT6110_G39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VT6110_G39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VT6110_G47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VT6110_G47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VT6110_G55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VT6110_G55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VT6110_G63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VT6110_G63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VT6110_G71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VT6110_G71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VT6110_G79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VT6110_G79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VT6110_G95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VT6110_G95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VT6110_G111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VT6110_G111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VT6110_G127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VT6110_G127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VT6110_G159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VT6110_G159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VT6110_G191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VT6110_G191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VT6110_G223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VT6110_G223.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VT6110_G255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VT6110_G255.Value.ToString())) & 0xff);

                    }
                    break;
                case "VT6110_GammaW_Blue":     //8
                    {
                        Send_buf[1] = 0x08;
                        Send_buf[3] = 0x81;
                        Send_buf[4] = (byte)(VT6110_Gamma_Group.Value);

                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(VT6110_B0.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(VT6110_B0.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(VT6110_B1.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(VT6110_B1.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(VT6110_B3.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(VT6110_B3.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(VT6110_B5.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(VT6110_B5.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(VT6110_B7.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(VT6110_B7.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(VT6110_B11.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(VT6110_B11.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(VT6110_B15.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(VT6110_B15.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(VT6110_B19.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(VT6110_B19.Value.ToString())) & 0xff);

                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(VT6110_B23.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(VT6110_B23.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(VT6110_B27.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(VT6110_B27.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(VT6110_B31.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(VT6110_B31.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(VT6110_B35.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(VT6110_B35.Value.ToString())) & 0xff);
                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(VT6110_B39.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(VT6110_B39.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(VT6110_B47.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(VT6110_B47.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(VT6110_B55.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(VT6110_B55.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(VT6110_B63.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(VT6110_B63.Value.ToString())) & 0xff);

                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(VT6110_B71.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(VT6110_B71.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(VT6110_B79.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(VT6110_B79.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(VT6110_B95.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(VT6110_B95.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(VT6110_B111.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(VT6110_B111.Value.ToString())) & 0xff);
                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(VT6110_B127.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(VT6110_B127.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(VT6110_B159.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(VT6110_B159.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(VT6110_B191.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(VT6110_B191.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(VT6110_B223.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(VT6110_B223.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(VT6110_B255.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(VT6110_B255.Value.ToString())) & 0xff);
                    }
                    break;
                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[55], out Send_buf[56]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 57);   //VT6110
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        public void VT6110_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x70;
            Send_buf[2] = 0x02;

            switch (btnTmp.Name)
            {
                case "VT_OTP": //otp Gamma
                    {
                        Send_buf[1] = 0x0D;
                        if (rbt_otp_p0.Checked == true)
                        { Send_buf[3] = 0x0F; }
                        else if (rbt_otp_p1.Checked == true)
                        { Send_buf[3] = 0x1B; }
                        else if (rbt_otp_p2.Checked == true)
                        { Send_buf[3] = 0x1C; }
                        else if (rbt_otp_p4.Checked == true)
                        { Send_buf[3] = 0x1A; }
                        else if (rbt_otp_p5.Checked == true)
                        { Send_buf[3] = 0x1D; }
                        else if (rbt_otp_p7.Checked == true)
                        { Send_buf[3] = 0x1E; }
                        else if (rbt_otp_p8.Checked == true)
                        { Send_buf[3] = 0x1F; }
                        else if (rbt_otp_all.Checked == true)
                        { Send_buf[3] = 0x0E; }
                        else if (rbt_otp_gamma.Checked == true)
                        { Send_buf[3] = 0x0D; }
                    }
                    break;
                //--------------------------------------------------------------------
                case "Read_Flash_ID":         //读Flash ID
                    {
                        Send_buf[1] = 0x20;
                    }
                    break;
                case "Erase_Flash":         //擦除Flash
                    {
                        Send_buf[1] = 0x21;
                        // frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Please Wait for 50 seconds\r\n";
                    }
                    break;
                case "Flash_Status":         //确认Flash Status
                    {
                        Send_buf[1] = 0x22;
                        //frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Check_Flash":         //确认Flash Status
                    {
                        Send_buf[1] = 0x23;
                        //frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "Five_Step":         //确认Flash Status
                    {
                        Send_buf[1] = 0x24;
                        //frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Please Wait for 30 seconds\r\n";
                    }
                    break;
                case "OTP_Flash":         //确认Flash Status
                    {
                        Send_buf[1] = 0x25;
                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "OTP Please Wait for 40 seconds\r\n";
                    }
                    break;
                case "CRC_check":
                    {
                        Send_buf[1] = 0x26;
                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "CRC_check\r\n";
                    }
                    break;
                case "Demura_on":
                    {
                        Send_buf[1] = 0x27;
                    }
                    break;
                case "Demura_off":
                    {
                        Send_buf[1] = 0x28;
                    }
                    break;
                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        public void VT6110_RegWR_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Int32 DataNum;
            string strLine = Convert.ToString(VT6110_txtRegData.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

            switch (btnTmp.Name)
            {
                case "VT6110_RegW":
                    {
                        Setting.TempRecord.cmdLen = arr.Length + 5;
                        Send_buf = new byte[arr.Length + 5];
                        Send_buf[0] = 0x70;//VT6110
                        Send_buf[1] = 0x01;
                        Send_buf[2] = byte.Parse(arr.Length.ToString());
                        for (int i = 0; i < arr.Length; i++)
                        {
                            Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                        }
                        CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + arr.Length);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                case "VT6110_RegR":
                    {
                        Setting.TempRecord.VT6110CmdType = 0x02;
                        try
                        {
                            DataNum = Convert.ToInt32(VT6110_txtDataNum.Text) + 1;
                            Setting.TempRecord.cmdLen = DataNum + 5;
                            Send_buf = new byte[DataNum + 5];
                            Send_buf[0] = 0x70; //VT6110
                            Send_buf[1] = 0x02;
                            Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                            Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());  //cmd
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                        }
                        catch
                        {
                            MessageBox.Show("读取长度有误，请检查", "错误");
                            break;
                        }
                        try
                        {
                            frmHelp.comPort.Write(Send_buf, 0, 5 + DataNum);
                        }
                        catch
                        {
                            MessageBox.Show("串口有误，请检查", "错误");
                        }
                    }
                    break;
                default: break;
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        public void VT6110_trackBar_Scroll(object sender, EventArgs e)
        {
            VT6110_label.Text = VT6110_51Reg_trackBar.Value.ToString() + "阶";
            VT6110_txtRegData.Text = "51,00," + VT6110_51Reg_trackBar.Value.ToString("x2");
            VT6110_RegWR_Click(VT6110_RegW, e);
        }
        public void btnCalculate_VT6110_Click(object sender, EventArgs e)
        {

        }

        public void btnAutoGammas_VT6110_Click(object sender, EventArgs e)
        {
            index = 0;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;

            if (cBx_AOD_Auto_Gamma.Checked == true)  //AOD gamma adjust in AOD mode or not
            {
                Load_GammmPic(Diven_Offset[index].NO.ToString()); //Load pic
            }
            else if (rbt_VT6110_IRC.Checked == true)
            {
                Load_GammmPic("P16"); //Load pic
            }
            else if (VT6130_Bist_Pattern.Checked == true)
            {
                R_bist.Value = Diven_Offset[index].NO;
                G_bist.Value = Diven_Offset[index].NO;
                B_bist.Value = Diven_Offset[index].NO;
                Application.DoEvents();
                bist_W_Click(null, null);
            }
            else
            {
                frmHelp.numPatternR.Value = Diven_Offset[index].NO;
                frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                frmHelp.numPatternB.Value = Diven_Offset[index].NO;
                Application.DoEvents();
                frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
            }
            Thread.Sleep(500);
            T20.Enabled = true;
        }
        public void btnVTStop_Click(object sender, EventArgs e)
        {
            T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
        }
        private void T20_Tick(object sender, EventArgs e)
        {
            if (rbt_VT6110_P15.Checked == true)
            {
                VT6110_Gamma_P15(null, null);
            }
            else if (rbt_VT6110_P25.Checked == true)
            {
                VT6110_Gamma_25P(null, null);
            }
            else if (rbt_VT6110_IRC.Checked == true)
            {
                VT6110_Gamma_IRC(null, null);
            }
        }

        private void BtnCalculateVT6110_Click(object sender, EventArgs e)
        {
            double L_X, L_Y, L_Z;
            string[] arr = VT6110_Gamma_SetBox.Lines;
            {
                try
                {
                    Diven_Gamma.Clear();
                    Diven_Offset.Clear();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        string line = arr[i];
                        line = line.Replace(" ", "");
                        if (line.Contains("TUNING_SPEC"))
                        {
                            line = line.Replace("TUNING_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr0 = line.Split(',');
                            Setting.Gamma_Property Gamma = new Setting.Gamma_Property(Convert.ToInt32(arr0[0]), Convert.ToDouble(arr0[1]), Convert.ToDouble(arr0[2]), Convert.ToDouble(arr0[3]), Convert.ToDouble(arr0[4]));
                            Diven_Gamma.Add(Gamma);
                        }
                        else if (line.Contains("LXY_SPEC"))
                        {
                            line = line.Replace("LXY_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr1 = line.Split(',');
                            //将Offset对象放入集合
                            Setting.Offset_Property Offset = new Setting.Offset_Property(Convert.ToInt32(arr1[0]), Convert.ToDouble(arr1[1]), Convert.ToDouble(arr1[2]), Convert.ToDouble(arr1[3]));
                            Diven_Offset.Add(Offset);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("格式输入有误");
                }
            }

            try  //获取调整spec
            {
                txtVT6110_loff.Text = Diven_Offset[0].LUM_OFF.ToString();
                txtVT6110_xoff.Text = Diven_Offset[0].X_OFF.ToString();
                txtVT6110_yoff.Text = Diven_Offset[0].Y_OFF.ToString();

                Total_points = Diven_Gamma[0].Points_num;
                D_lums = new double[Total_points, 3];
                D_lum = new double[Total_points];

                txtVT6110_gamma.Text = Diven_Gamma[0].Curve.ToString();
                txtVT6110_lum.Text = Diven_Gamma[0].Lum.ToString();
                txtVT6110_x.Text = Diven_Gamma[0].X.ToString();
                txtVT6110_y.Text = Diven_Gamma[0].Y.ToString();

                for (int i = 0; i < Total_points; i++)
                {   //Diven_Offset[p].NO 灰阶绑点                 
                    D_lum[i] = (Math.Pow((Diven_Offset[i].NO / 255.0), Diven_Gamma[0].Curve) * Diven_Gamma[0].Lum); //每绑点目标亮度
                    CaSDKObj.Lvxy_to_XYZ(D_lum[i], Diven_Gamma[0].X, Diven_Gamma[0].Y, out L_X, out L_Y, out L_Z);//X/Z/Z转换
                    D_lums[i, 0] = L_X; //R/B/G分亮度计算
                    D_lums[i, 1] = L_Y;
                    D_lums[i, 2] = L_Z;
                }
            }
            catch
            {
                MessageBox.Show("格式输入有误");
            }
        }

        public void VT6110_Gamma_P15(Object myObject, EventArgs myEventArgs)
        {
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }
            }

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                frmHelp.Gamma_auto_adjust_count_set = 40;
                //--------
                index++;

                if (index == Diven_Gamma[0].Points_num)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110 gamma调试完毕!\r\n";
                    //---------------------------------add-------------------------------------
                    if (Multi_gamma_txt_next_index < Multi_gamma_txt_line_count)
                    {
                        Multi_gamma_txt_now_index = Multi_gamma_txt_next_index;
                        Multi_flexible_gammas(Multi_gamma_txt_now_index, out Multi_gamma_txt_next_index);
                    }
                    //---------------------------------add-------------------------------------
                }
                if (index < Diven_Gamma[0].Points_num)
                {
                    if (cBx_AOD_Auto_Gamma.Checked == true)  //AOD gamma adjust in AOD mode or not
                    {
                        Load_GammmPic(Diven_Offset[index].NO.ToString()); //Load pic
                    }
                    else if (VT6130_Bist_Pattern.Checked == true)
                    {
                        R_bist.Value = Diven_Offset[index].NO;
                        G_bist.Value = Diven_Offset[index].NO;
                        B_bist.Value = Diven_Offset[index].NO;
                        Application.DoEvents();
                        Bist_Setting((byte)(R_bist.Value), (byte)(G_bist.Value), (byte)(B_bist.Value));
                    }
                    else
                    {
                        frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                        frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                        frmHelp.numPatternB.Value = Diven_Offset[index].NO;
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数
                    }
                    Thread.Sleep(1000); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;
                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_R223.Value = r - 10; VT6110_G223.Value = g - 10; VT6110_B223.Value = b - 10;
                                }
                            }
                            break;
                        case 1:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R223.Value, VT6110_G223.Value, VT6110_B223.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R223.Value = r;
                                VT6110_G223.Value = g;
                                VT6110_B223.Value = b;
                                if (VT6110_G223.Value <= VT6110_G191.Value)
                                {
                                    VT6110_R191.Value = r - 20; VT6110_G191.Value = g - 20; VT6110_B191.Value = b - 20;
                                }
                            }
                            break;
                        case 2:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R191.Value, VT6110_G191.Value, VT6110_B191.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R191.Value = r;
                                VT6110_G191.Value = g;
                                VT6110_B191.Value = b;
                                if (VT6110_G191.Value <= VT6110_G127.Value)
                                {
                                    VT6110_R127.Value = r - 20; VT6110_G127.Value = g - 20; VT6110_B127.Value = b - 20;
                                }
                            }
                            break;

                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R127.Value, VT6110_G127.Value, VT6110_B127.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R127.Value = r;
                                VT6110_G127.Value = g;
                                VT6110_B127.Value = b;
                                if (VT6110_G127.Value <= VT6110_G111.Value)
                                {
                                    VT6110_R111.Value = r - 20; VT6110_G111.Value = g - 20; VT6110_B111.Value = b - 20;
                                }
                            }
                            break;

                        case 4:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R111.Value, VT6110_G111.Value, VT6110_B111.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R111.Value = r;
                                VT6110_G111.Value = g;
                                VT6110_B111.Value = b;
                                if (VT6110_G111.Value <= VT6110_G79.Value)
                                {
                                    VT6110_R79.Value = r - 20; VT6110_G79.Value = g - 20; VT6110_B79.Value = b - 20;
                                }
                            }
                            break;

                        case 5:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R79.Value, VT6110_G79.Value, VT6110_B79.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R79.Value = r;
                                VT6110_G79.Value = g;
                                VT6110_B79.Value = b;
                                if (VT6110_G79.Value <= VT6110_G63.Value)
                                {
                                    VT6110_R63.Value = r - 20; VT6110_G63.Value = g - 20; VT6110_B63.Value = b - 20;
                                }
                            }
                            break;

                        case 6:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R63.Value, VT6110_G63.Value, VT6110_B63.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R63.Value = r;
                                VT6110_G63.Value = g;
                                VT6110_B63.Value = b;
                                if (VT6110_G63.Value <= VT6110_G55.Value)
                                {
                                    VT6110_R55.Value = r - 20; VT6110_G55.Value = g - 20; VT6110_B55.Value = b - 20;
                                }
                            }
                            break;

                        case 7:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R55.Value, VT6110_G55.Value, VT6110_B55.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R55.Value = r;
                                VT6110_G55.Value = g;
                                VT6110_B55.Value = b;
                                if (VT6110_G55.Value <= VT6110_G47.Value)
                                {
                                    VT6110_R47.Value = r - 20; VT6110_G47.Value = g - 20; VT6110_B47.Value = b - 20;
                                }
                            }
                            break;

                        case 8:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R47.Value, VT6110_G47.Value, VT6110_B47.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R47.Value = r;
                                VT6110_G47.Value = g;
                                VT6110_B47.Value = b;
                                if (VT6110_G47.Value <= VT6110_G39.Value)
                                {
                                    VT6110_R39.Value = r - 20; VT6110_G39.Value = g - 20; VT6110_B39.Value = b - 20;
                                }
                            }
                            break;

                        case 9:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R39.Value, VT6110_G39.Value, VT6110_B39.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R39.Value = r;
                                VT6110_G39.Value = g;
                                VT6110_B39.Value = b;
                                if (VT6110_G39.Value <= VT6110_G35.Value)
                                {
                                    VT6110_R35.Value = r - 20; VT6110_G35.Value = g - 20; VT6110_B35.Value = b - 20;
                                }
                            }
                            break;

                        case 10:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R35.Value, VT6110_G35.Value, VT6110_B35.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R35.Value = r;
                                VT6110_G35.Value = g;
                                VT6110_B35.Value = b;
                                if (VT6110_G35.Value <= VT6110_G31.Value)
                                {
                                    VT6110_R31.Value = r - 20; VT6110_G31.Value = g - 20; VT6110_B31.Value = b - 20;
                                }
                            }
                            break;

                        case 11:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R31.Value, VT6110_G31.Value, VT6110_B31.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R31.Value = r;
                                VT6110_G31.Value = g;
                                VT6110_B31.Value = b;
                                if (VT6110_G31.Value <= VT6110_G11.Value)
                                {
                                    VT6110_R11.Value = r - 20; VT6110_G11.Value = g - 20; VT6110_B11.Value = b - 20;
                                }
                            }
                            break;

                        case 12:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R11.Value, VT6110_G11.Value, VT6110_B11.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R11.Value = r;
                                VT6110_G11.Value = g;
                                VT6110_B11.Value = b;
                                if (VT6110_G11.Value <= VT6110_G3.Value)
                                {
                                    VT6110_R3.Value = r - 20; VT6110_G3.Value = g - 20; VT6110_B3.Value = b - 20;
                                }
                            }
                            break;
                        case 13:
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R1.Value = (int)(VT6110_R3.Value / 2);
                                VT6110_G1.Value = (int)(VT6110_G3.Value / 2);
                                VT6110_B1.Value = (int)(VT6110_B3.Value / 2);
                            }
                            break;
                        case 14: //
                            {
                                Gamma_adjust_timeout_flag = true;
                                VT6110_R0.Value = 0;
                                VT6110_G0.Value = 0;
                                VT6110_B0.Value = 0;
                                Application.DoEvents();
                            }
                            break;
                        default:
                            break;
                    }
                    VT6110_GAMMA_Click(VT6110_GammaW_Red, null);
                    Thread.Sleep(20);
                    VT6110_GAMMA_Click(VT6110_GammaW_Green, null);
                    Thread.Sleep(20);
                    VT6110_GAMMA_Click(VT6110_GammaW_Blue, null);
                    Thread.Sleep(20);
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");
                }
            }
        }
        public void VT6110_Gamma_25P(Object myObject, EventArgs myEventArgs)
        {
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }
            }

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;
                //--------
                index++;

                if (index == Diven_Gamma[0].Points_num)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110 gamma调试完毕!\r\n";
                    //---------------------------------add-------------------------------------
                    if (Multi_gamma_txt_next_index < Multi_gamma_txt_line_count)
                    {
                        Multi_gamma_txt_now_index = Multi_gamma_txt_next_index;
                        Multi_flexible_gammas(Multi_gamma_txt_now_index, out Multi_gamma_txt_next_index);
                    }
                    //---------------------------------add-------------------------------------
                }
                if (index < Diven_Gamma[0].Points_num)
                {
                    if (cBx_AOD_Auto_Gamma.Checked == true)  //AOD gamma adjust in AOD mode or not
                    {
                        Load_GammmPic(Diven_Offset[index].NO.ToString()); //Load pic
                    }
                    else if (VT6130_Bist_Pattern.Checked == true)
                    {
                        R_bist.Value = Diven_Offset[index].NO;
                        G_bist.Value = Diven_Offset[index].NO;
                        B_bist.Value = Diven_Offset[index].NO;
                        Application.DoEvents();
                        Bist_Setting((byte)(R_bist.Value), (byte)(G_bist.Value), (byte)(B_bist.Value));
                    }
                    else
                    {
                        frmHelp.numPatternR.Value = Diven_Offset[index].NO;//固定255灰阶
                        frmHelp.numPatternG.Value = Diven_Offset[index].NO;
                        frmHelp.numPatternB.Value = Diven_Offset[index].NO;
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnPatternW, null);//写入Pattern参数
                    }
                    Thread.Sleep(50); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 50;
                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 75;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                                // auto_gamma_write(gamma_r[index], Convert.ToUInt16(RM692AX_R32.Value), gamma_g[index], Convert.ToUInt16(RM692AX_G32.Value), gamma_b[index], Convert.ToUInt16(RM692AX_B32.Value));
                            }
                            break;
                        case 1:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 55;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R223.Value, VT6110_G223.Value, VT6110_B223.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R223.Value = r;
                                VT6110_G223.Value = g;
                                VT6110_B223.Value = b;
                                if (VT6110_G223.Value <= VT6110_G191.Value)
                                {
                                    VT6110_R191.Value = r - 10; VT6110_G191.Value = g - 10; VT6110_B191.Value = b - 10;
                                }
                            }
                            break;
                        case 2:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R191.Value, VT6110_G191.Value, VT6110_B191.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R191.Value = r;
                                VT6110_G191.Value = g;
                                VT6110_B191.Value = b;
                                if (VT6110_G191.Value <= VT6110_G159.Value)
                                {
                                    VT6110_R159.Value = r - 20; VT6110_G159.Value = g - 20; VT6110_B159.Value = b - 20;
                                }
                            }
                            break;

                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R159.Value, VT6110_G159.Value, VT6110_B159.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R159.Value = r;
                                VT6110_G159.Value = g;
                                VT6110_B159.Value = b;
                                if (VT6110_G159.Value <= VT6110_G127.Value)
                                {
                                    VT6110_R127.Value = r - 20; VT6110_G127.Value = g - 20; VT6110_B127.Value = b - 20;
                                }
                            }
                            break;
                        case 4:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 35;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R127.Value, VT6110_G127.Value, VT6110_B127.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R127.Value = r;
                                VT6110_G127.Value = g;
                                VT6110_B127.Value = b;
                                if (VT6110_G127.Value <= VT6110_G111.Value)
                                {
                                    VT6110_R111.Value = r - 20; VT6110_G111.Value = g - 20; VT6110_B111.Value = b - 20;
                                }
                            }
                            break;
                        case 5:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R111.Value, VT6110_G111.Value, VT6110_B111.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R111.Value = r;
                                VT6110_G111.Value = g;
                                VT6110_B111.Value = b;
                                if (VT6110_G111.Value <= VT6110_G95.Value)
                                {
                                    VT6110_R95.Value = r - 20; VT6110_G95.Value = g - 20; VT6110_B95.Value = b - 20;
                                }
                            }
                            break;
                        case 6:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 32;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R95.Value, VT6110_G95.Value, VT6110_B95.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R95.Value = r;
                                VT6110_G95.Value = g;
                                VT6110_B95.Value = b;
                                if (VT6110_G95.Value <= VT6110_G79.Value)
                                {
                                    VT6110_R79.Value = r - 20; VT6110_G79.Value = g - 20; VT6110_B79.Value = b - 20;
                                }
                            }
                            break;
                        case 7:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R79.Value, VT6110_G79.Value, VT6110_B79.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R79.Value = r;
                                VT6110_G79.Value = g;
                                VT6110_B79.Value = b;
                                if (VT6110_G79.Value <= VT6110_G71.Value)
                                {
                                    VT6110_R71.Value = r - 20; VT6110_G71.Value = g - 20; VT6110_B71.Value = b - 20;
                                }
                            }
                            break;
                        case 8:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 25;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R71.Value, VT6110_G71.Value, VT6110_B71.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R71.Value = r;
                                VT6110_G71.Value = g;
                                VT6110_B71.Value = b;
                                if (VT6110_G71.Value <= VT6110_G63.Value)
                                {
                                    VT6110_R63.Value = r - 20; VT6110_G63.Value = g - 20; VT6110_B63.Value = b - 20;
                                }
                            }
                            break;
                        case 9:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R63.Value, VT6110_G63.Value, VT6110_B63.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R63.Value = r;
                                VT6110_G63.Value = g;
                                VT6110_B63.Value = b;
                                if (VT6110_G63.Value <= VT6110_G55.Value)
                                {
                                    VT6110_R55.Value = r - 20; VT6110_G55.Value = g - 20; VT6110_B55.Value = b - 20;
                                }
                            }
                            break;
                        case 10:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R55.Value, VT6110_G55.Value, VT6110_B55.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R55.Value = r;
                                VT6110_G55.Value = g;
                                VT6110_B55.Value = b;
                                if (VT6110_G55.Value <= VT6110_G47.Value)
                                {
                                    VT6110_R47.Value = r - 20; VT6110_G47.Value = g - 20; VT6110_B47.Value = b - 20;
                                }
                            }
                            break;
                        case 11:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R47.Value, VT6110_G47.Value, VT6110_B47.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R47.Value = r;
                                VT6110_G47.Value = g;
                                VT6110_B47.Value = b;
                                if (VT6110_G47.Value <= VT6110_G39.Value)
                                {
                                    VT6110_R39.Value = r - 20; VT6110_G39.Value = g - 20; VT6110_B39.Value = b - 20;
                                }
                            }
                            break;
                        case 12:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R39.Value, VT6110_G39.Value, VT6110_B39.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R39.Value = r;
                                VT6110_G39.Value = g;
                                VT6110_B39.Value = b;
                                if (VT6110_G39.Value <= VT6110_G35.Value)
                                {
                                    VT6110_R35.Value = r - 20; VT6110_G35.Value = g - 20; VT6110_B35.Value = b - 20;
                                }
                            }
                            break;
                        case 13:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R35.Value, VT6110_G35.Value, VT6110_B35.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R35.Value = r;
                                VT6110_G35.Value = g;
                                VT6110_B35.Value = b;
                                if (VT6110_G35.Value <= VT6110_G31.Value)
                                {
                                    VT6110_R31.Value = r - 20; VT6110_G31.Value = g - 20; VT6110_B31.Value = b - 20;
                                }
                            }
                            break;
                        case 14:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R31.Value, VT6110_G31.Value, VT6110_B31.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R35.Value)
                                {
                                    r = VT6110_R35.Value - 1;
                                }
                                if (g > VT6110_G35.Value)
                                {
                                    g = VT6110_G35.Value - 1;
                                }
                                if (b > VT6110_B35.Value)
                                {
                                    b = VT6110_B31.Value - 1;
                                }
                                VT6110_R31.Value = r;
                                VT6110_G31.Value = g;
                                VT6110_B31.Value = b;
                                if (VT6110_G31.Value <= VT6110_G27.Value)
                                {
                                    VT6110_R27.Value = r - 20; VT6110_G27.Value = g - 20; VT6110_B27.Value = b - 20;
                                }
                            }
                            break;
                        case 15:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 21;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R27.Value, VT6110_G27.Value, VT6110_B27.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R31.Value)
                                {
                                    r = VT6110_R31.Value - 1;
                                }
                                if (g > VT6110_G31.Value)
                                {
                                    g = VT6110_G31.Value - 1;
                                }
                                if (b > VT6110_B31.Value)
                                {
                                    b = VT6110_B31.Value - 1;
                                }
                                VT6110_R27.Value = r;
                                VT6110_G27.Value = g;
                                VT6110_B27.Value = b;
                                if (VT6110_G27.Value <= VT6110_G23.Value)
                                {
                                    VT6110_R23.Value = r - 20; VT6110_G23.Value = g - 20; VT6110_B23.Value = b - 20;
                                }
                            }
                            break;
                        case 16:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R23.Value, VT6110_G23.Value, VT6110_B23.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R27.Value)
                                {
                                    r = VT6110_R27.Value - 1;
                                }
                                if (g > VT6110_G27.Value)
                                {
                                    g = VT6110_G27.Value - 1;
                                }
                                if (b > VT6110_B27.Value)
                                {
                                    b = VT6110_B27.Value - 1;
                                }
                                VT6110_R23.Value = r;
                                VT6110_G23.Value = g;
                                VT6110_B23.Value = b;
                                if (VT6110_G23.Value <= VT6110_G19.Value)
                                {
                                    VT6110_R19.Value = r - 15; VT6110_G19.Value = g - 15; VT6110_B19.Value = b - 15;
                                }
                            }
                            break;
                        case 17:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R19.Value, VT6110_G19.Value, VT6110_B19.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R23.Value)
                                {
                                    r = VT6110_R23.Value - 1;
                                }
                                if (g > VT6110_G23.Value)
                                {
                                    g = VT6110_G23.Value - 1;
                                }
                                if (b > VT6110_B23.Value)
                                {
                                    b = VT6110_B23.Value - 1;
                                }
                                VT6110_R19.Value = r;
                                VT6110_G19.Value = g;
                                VT6110_B19.Value = b;
                                if (VT6110_G19.Value <= VT6110_G15.Value)
                                {
                                    VT6110_R15.Value = r - 10; VT6110_G15.Value = g - 10; VT6110_B15.Value = b - 10;
                                }
                            }
                            break;
                        case 18:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R15.Value, VT6110_G15.Value, VT6110_B15.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R19.Value)
                                {
                                    r = VT6110_R19.Value - 1;
                                }
                                if (g > VT6110_G19.Value)
                                {
                                    g = VT6110_G19.Value - 1;
                                }
                                if (b > VT6110_B19.Value)
                                {
                                    b = VT6110_B19.Value - 1;
                                }
                                VT6110_R15.Value = r;
                                VT6110_G15.Value = g;
                                VT6110_B15.Value = b;
                                if (VT6110_G15.Value <= VT6110_G11.Value)
                                {
                                    VT6110_R11.Value = r - 10; VT6110_G11.Value = g - 10; VT6110_B11.Value = b - 10;
                                }
                            }
                            break;
                        case 19:
                            {
                                frmHelp.Gamma_auto_adjust_count_set = 15;
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R11.Value, VT6110_G11.Value, VT6110_B11.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R15.Value)
                                {
                                    r = VT6110_R15.Value - 1;
                                }
                                if (g > VT6110_G15.Value)
                                {
                                    g = VT6110_G15.Value - 1;
                                }
                                if (b > VT6110_B15.Value)
                                {
                                    b = VT6110_B15.Value - 1;
                                }
                                VT6110_R11.Value = r;
                                VT6110_G11.Value = g;
                                VT6110_B11.Value = b;
                                if (VT6110_G11.Value <= VT6110_G7.Value)
                                {
                                    VT6110_R7.Value = r - 10; VT6110_G7.Value = g - 10; VT6110_B7.Value = b - 10;
                                }
                            }
                            break;
                        case 20:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R7.Value, VT6110_G7.Value, VT6110_B7.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R11.Value)
                                {
                                    r = VT6110_R11.Value - 1;
                                }
                                if (g > VT6110_G11.Value)
                                {
                                    g = VT6110_G11.Value - 1;
                                }
                                if (b > VT6110_B11.Value)
                                {
                                    b = VT6110_B11.Value - 1;
                                }
                                VT6110_R7.Value = r;
                                VT6110_G7.Value = g;
                                VT6110_B7.Value = b;
                                if (VT6110_G7.Value <= VT6110_G5.Value)
                                {
                                    VT6110_R5.Value = r - 10; VT6110_G5.Value = g - 10; VT6110_B5.Value = b - 10;
                                }
                            }
                            break;
                        case 21:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R5.Value, VT6110_G5.Value, VT6110_B5.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R7.Value)
                                {
                                    r = VT6110_R7.Value - 1;
                                }
                                if (g > VT6110_G7.Value)
                                {
                                    g = VT6110_G7.Value - 1;
                                }
                                if (b > VT6110_B7.Value)
                                {
                                    b = VT6110_B7.Value - 1;
                                }
                                VT6110_R5.Value = r;
                                VT6110_G5.Value = g;
                                VT6110_B5.Value = b;
                                if (VT6110_G5.Value <= VT6110_G3.Value)
                                {
                                    VT6110_R3.Value = r - 5; VT6110_G3.Value = g - 5; VT6110_B3.Value = b - 5;
                                }
                            }
                            break;
                        case 22:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R3.Value, VT6110_G3.Value, VT6110_B3.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                if (r > VT6110_R5.Value)
                                {
                                    r = VT6110_R5.Value - 1;
                                }
                                if (g > VT6110_G5.Value)
                                {
                                    g = VT6110_G5.Value - 1;
                                }
                                if (b > VT6110_B5.Value)
                                {
                                    b = VT6110_B5.Value - 1;
                                }
                                VT6110_R3.Value = r;
                                VT6110_G3.Value = g;
                                VT6110_B3.Value = b;
                                if (VT6110_R3.Value <= VT6110_R1.Value || VT6110_G3.Value <= VT6110_G1.Value || VT6110_B3.Value <= VT6110_B1.Value)
                                {
                                    VT6110_R1.Value = r - 1; VT6110_G1.Value = g - 1; VT6110_B1.Value = b - 1;
                                }
                                if (VT6110_G3.Value <= 0xf || VT6110_R3.Value <= 0xf || VT6110_B3.Value <= 0xf)
                                {
                                    Gamma_adjust_timeout_flag = true;
                                }
                            }
                            break;
                        case 23:
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R1.Value = (int)(VT6110_R3.Value / 2);
                                VT6110_G1.Value = (int)(VT6110_G3.Value / 2);
                                VT6110_B1.Value = (int)(VT6110_B3.Value / 2);
                            }
                            break;
                        case 24:
                            {
                                Gamma_adjust_timeout_flag = true;
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R0.Value = 0;
                                VT6110_G0.Value = 0;
                                VT6110_B0.Value = 0;
                            }
                            break;
                        default:
                            break;
                    }

                    VT6110_GAMMA_Click(VT6110_GammaW_Red, null);
                    Thread.Sleep(20);
                    VT6110_GAMMA_Click(VT6110_GammaW_Green, null);
                    Thread.Sleep(20);
                    VT6110_GAMMA_Click(VT6110_GammaW_Blue, null);
                    Thread.Sleep(20);
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");

                }
            }
        }
        public void VT6110_Gamma_IRC(Object myObject, EventArgs myEventArgs)
        {
            double L_X, L_Y, L_Z, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();
            if (Gamma_adjust_timeout_flag == true)//如果是0绑点
            {
                flag1 = 0;
                flag2 = 0;
                flag3 = 0;
            }
            else
            {
                if ((frmHelp.CASDK_LUM < (D_lum[index] + D_lum[index] * Diven_Offset[index].LUM_OFF / 100)) && (frmHelp.CASDK_LUM > (D_lum[index] - D_lum[index] * Diven_Offset[index].LUM_OFF / 100)))//G
                { flag1 = 0; }
                else
                { flag1 = 1; }
                if ((frmHelp.CASDK_x < (Diven_Gamma[0].X + Diven_Offset[index].X_OFF)) && (frmHelp.CASDK_x > (Diven_Gamma[0].X - Diven_Offset[index].X_OFF)) && flag1 == 0)//R
                { flag3 = 0; }
                else
                { flag3 = 1; }
                if ((frmHelp.CASDK_y < (Diven_Gamma[0].Y + Diven_Offset[index].Y_OFF)) && (frmHelp.CASDK_y > (Diven_Gamma[0].Y - Diven_Offset[index].Y_OFF)) && flag1 == 0 && flag3 == 0)//B
                { flag2 = 0; }
                else
                { flag2 = 1; }
            }

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                T20.Enabled = false;
                //reset-----
                Gamma_adjust_timeout_flag = false;
                frmHelp.Gamma_auto_adjust_count = 0;
                frmHelp.Gamma_auto_adjust_count_set = 40;
                //--------
                RR[index] = VT6110_R255.Value;
                GG[index] = VT6110_G255.Value;
                BB[index] = VT6110_B255.Value;

                index++;

                if (index == Diven_Gamma[0].Points_num)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "VT6110 IRC Gamma调试完毕!\r\n";
                    //---------------------------------add-------------------------------------
                    if (Multi_gamma_txt_next_index < Multi_gamma_txt_line_count)
                    {
                        Multi_gamma_txt_now_index = Multi_gamma_txt_next_index;
                        Multi_flexible_gammas(Multi_gamma_txt_now_index, out Multi_gamma_txt_next_index);
                    }
                    //---------------------------------add-------------------------------------
                    dataGridView_BestGC.Rows.Clear();
                    dataGridView_BestGC.Rows.Add("16.91%", RR[0].ToString(), GG[0].ToString(), BB[0].ToString());
                    dataGridView_BestGC.Rows.Add("33.33%", RR[1].ToString(), GG[1].ToString(), BB[1].ToString());
                    dataGridView_BestGC.Rows.Add("50%", RR[2].ToString(), GG[2].ToString(), BB[2].ToString());
                    dataGridView_BestGC.Rows.Add("75%", RR[3].ToString(), GG[3].ToString(), BB[3].ToString());
                    dataGridView_BestGC.Rows.Add("100%", RR[4].ToString(), GG[4].ToString(), BB[4].ToString());
                }
                if (index < Diven_Gamma[0].Points_num)
                {
                    switch (index)
                    {
                        case 0:
                            Load_GammmPic("P16"); //Load pic
                            break;
                        case 1:
                            Load_GammmPic("P33"); //Load pic
                            break;
                        case 2:
                            Load_GammmPic("P50"); //Load pic
                            break;
                        case 3:
                            Load_GammmPic("P75"); //Load pic
                            break;
                        case 4:
                            Load_GammmPic("P100"); //Load pic
                            break;
                    }
                    Thread.Sleep(500); //1秒=1000毫秒，
                    T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                decimal r = 0, g = 0, b = 0;
                frmHelp.Gamma_auto_adjust_count_set = 70;
                CaSDKObj.Lvxy_to_XYZ(frmHelp.CASDK_LUM, frmHelp.CASDK_x, frmHelp.CASDK_y, out L_X, out L_Y, out L_Z);
                lumr = L_X;
                lumg = L_Y;
                lumb = L_Z;

                try
                {
                    switch (index)
                    {
                        case 0:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                            }
                            break;
                        case 1:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                            }
                            break;
                        case 2:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                            }
                            break;

                        case 3:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                            }
                            break;
                        case 4:
                            {
                                frmHelp.Flexible_Gamma_auto_Adujst(flag1, flag3, flag2, lumg, lumr, lumb, D_lums[index, 1], D_lums[index, 0], D_lums[index, 2], VT6110_R255.Value, VT6110_G255.Value, VT6110_B255.Value, Diven_Offset[index].NO, 0x3FF, out r, out g, out b, out Gamma_adjust_timeout_flag);
                                if (Gamma_adjust_timeout_flag == true)
                                {
                                    flag1 = 0; flag3 = 0; flag2 = 0;
                                }
                                VT6110_R255.Value = r;
                                VT6110_G255.Value = g;
                                VT6110_B255.Value = b;

                                if (VT6110_R255.Value <= VT6110_R223.Value)
                                {
                                    VT6110_R223.Value = r - 20;
                                }
                                if (VT6110_G255.Value <= VT6110_G223.Value)
                                {
                                    VT6110_G223.Value = g - 20;
                                }
                                if (VT6110_B255.Value <= VT6110_B223.Value)
                                {
                                    VT6110_B223.Value = b - 20;
                                }
                            }
                            break;
                        default:
                            break;
                    }

                    VT6110_GAMMA_Click(VT6110_GammaW_Red, null);
                    Thread.Sleep(60);
                    VT6110_GAMMA_Click(VT6110_GammaW_Green, null);
                    Thread.Sleep(60);
                    VT6110_GAMMA_Click(VT6110_GammaW_Blue, null);
                    Thread.Sleep(60);
                }
                catch
                {
                    T20.Enabled = false;
                    MessageBox.Show("调整数值超限");

                }
            }
        }

        private void bist_W_Click(object sender, EventArgs e)
        {
            Bist_Setting((byte)(R_bist.Value), (byte)(G_bist.Value), (byte)(B_bist.Value));
        }
        private void Bist_Setting(byte RR, byte GG, byte BB)
        {
            byte[] TepArr;
            byte brr, bgg, bbb;

            //   GrayLevel = (byte)R_bist.Value;
            if (rbt_VT6110_P25.Checked)
            {
                TepArr = new byte[] {
                        3,0xF0,0xAA,0x17,
                        5,0xB1,0x00,0x00,0x12,0x00,
                        23,0xB2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x40,0x00,
                        19,0xB3,0x00,0x40,0x00,0x00,0x40,0x00,0x80,0xC0,0x80,0x80,0xC0,0x80,0x00,0x40,0x00,0x00,0x40,0x00,
                        3,0xf0,0xaa,0x11,
                        5,0xde,0xaa,0x55,0x01,0x80,
                        9,0xdf,0x00,0x00,0x20,0x00,0x00,RR,GG,BB
                       };
            }
            else if (rbt_VT6110_AOD.Checked)
            {

                brr = bgg = bbb = 0; //背景色；
                TepArr = new byte[] {
                        //1,39,   //进AOD
                        2,0x6c,0x00,
                        2,0x6d,0x00,
                        1,0x39,
                        3,0xF0,0xAA,0x17,
                        5,0xB1,0x00,0x00,0x12,0x00,
                        23,0xB2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x40,0x00,
                        19,0xB3,0x00,0x40,0x00,0x00,0x40,0x00,0x80,0xC0,0x80,0x80,0xC0,0x80,0x00,0x40,0x00,0x00,0x40,0x00,
                        3,0xF0,0xAA,0x11,
                        4,0XFF,0XFF,0XFF,0X0F,
                        5,0xDE,0xAA,0x55,0x01,0x80,
                        9,0xDF,00,01,00,00,00,brr,bgg,bbb,    //背景色
                        2,0x65,0x08,  //跳转到第八个参数位置
                        12,0xDF,RR,GG,BB,0x00,0xE4,0x03,0x54,0x03,0x78,0x05,0xE8
                       };
            }
            else
            {
                return;
            }

            try
            {
                frmHelp.comPort.Write(GetCRCArray(TepArr, 4), 0, TepArr.Length + 6);//循环部分，每段数据结尾                  
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
                return;
            }
        }

        static byte[] GetCRCArray(byte[] arr, Byte speedflag)   //处理命令数组，在其头尾增加包头以及CRC校验值，处理后的数据可以直接发送至下位机
        {
            CRC16 CRCData = new CRC16();

            int arrNumbuer;                                                                                                                                                                                                                                                                                                                                             //51
            arrNumbuer = arr.Length;
            arrNumbuer += 6;
            byte[] Send_Datax = new byte[arrNumbuer];
            Send_Datax[0] = 0x9f;
            Send_Datax[1] = (byte)(speedflag << 4);
            Send_Datax[2] = Convert.ToByte(arr.Length + 1);  //为兼容下位机命令，此位置填待传输有效数据长度+1 

            Send_Datax[arr.Length + 3] = 0xFF;  //添加结束标志位
            arr.CopyTo(Send_Datax, 3);//合并数组头 4个Byte 标志位
            //计算校验码                                                 
            CRCData.CalculateCrc16(Send_Datax, out Send_Datax[arrNumbuer - 2], out Send_Datax[arrNumbuer - 1]);
            return Send_Datax;
        }
        private void Btn_load_gamma_patten_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fldb = new FolderBrowserDialog();
            fldb.ShowNewFolderButton = false;
            DialogResult res = fldb.ShowDialog();
            if (res != System.Windows.Forms.DialogResult.OK)
            {
                MessageBox.Show("没选择任何文件夹.");
                return;
            }
            Gamma_loading_path.Text = fldb.SelectedPath;

            if (!Directory.Exists(Gamma_loading_path.Text))
            {
                MessageBox.Show("文件夹不存在.");
                return;
            }
        }

        private void VT6110_Gamma_Load(object sender, EventArgs e)
        {

        }

        private void Load_GammmPic(string filenames)      //双击 载入 BMP图片
        {
            Int32 HACT_True = 0;
            Int32 HACT_Skip = 0;
            Int32 VACT_True = 0;
            Int32 m_txlen = 0;
            Int32 j = 0;
            FileStream aFile;

            //byte[] TemFileContent = new byte[1024 * 100];
            byte[] TemFileContent = new byte[512 * 4000 + 100];
            System.Int32 ByteReaded = 0x00;

            string FileName = Gamma_loading_path.Text + '\\' + filenames + ".bmp";
            aFile = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            ByteReaded = aFile.Read(TemFileContent, 0, 54);

            HACT_True = ((TemFileContent[19]) << 8) + TemFileContent[18];
            VACT_True = ((TemFileContent[23] << 8) + TemFileContent[22]);

            HACT_Skip = HACT_True;
            try
            { //5a a5 9DF0731A-----提前下个标志位告诉下位机开始送图了，避免特殊图片格式导致错误配置
                TemFileContent[0] = 0xbd; TemFileContent[1] = 0x5a; TemFileContent[2] = 0xa5; TemFileContent[3] = 0x9d; TemFileContent[4] = 0xf0;
                frmHelp.comPort.Write(TemFileContent, 0, 5);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
                return;
            }
            //-----------------------------------
            try
            {
                j = 1;
                aFile.Seek(54, SeekOrigin.Begin);
                while (j <= VACT_True)
                {
                    if (HACT_True % 4 != 0)
                        aFile.Seek((VACT_True - j) * (HACT_True * 3 + (HACT_True % 4)) + 54, SeekOrigin.Begin);
                    else
                        aFile.Seek((VACT_True - j) * HACT_True * 3 + 54, SeekOrigin.Begin);

                    ByteReaded = aFile.Read(TemFileContent, 0, HACT_True * 3); // 
                    try
                    {
                        frmHelp.comPort.Write(TemFileContent, 0, HACT_Skip * 3);
                    }
                    catch
                    {
                        MessageBox.Show("串口有误，请检查", "错误");
                        break;
                    }
                    m_txlen += ByteReaded;
                    j++;
                }

                TemFileContent[0] = 0x5A;
                try
                {
                    frmHelp.comPort.Write(TemFileContent, 0, 1);
                }
                catch
                {
                    MessageBox.Show("串口有误，请检查", "错误");
                    return;
                }
                aFile.Close();
            }
            catch
            {
                frmHelp.textBox1.Text += "啥图片都没显示";
                frmHelp.textBox1.Select(frmHelp.textBox1.Text.Length, 0);
                frmHelp.textBox1.ScrollToCaret();
            }
        }


        //---------------------------------add-------------------------------------
        private int Multi_gamma_txt_now_index = 0;
        private int Multi_gamma_txt_next_index;
        private int Multi_gamma_txt_line_count = 0;
        private int Multi_gamma_group_index = 0;
        private void Btn_flexible_gamma_Click(object sender, EventArgs e)
        {
            Multi_gamma_txt_now_index = 0;
            Multi_gamma_txt_line_count = this.VT6110_Gamma_SetBox.Lines.GetUpperBound(0);
            Multi_flexible_gammas(Multi_gamma_txt_now_index, out Multi_gamma_txt_next_index);
        }
        private void Multi_flexible_gammas(int txt_index, out int list_view_index)
        {
            string strLine = Convert.ToString(VT6110_Gamma_SetBox.Text);
            string[] arr = strLine.Split(','); //以逗号分割，添加到数组
            string perline = string.Empty;
            string perline0 = string.Empty;
            list_view_index = 0;

            if (VT6110_Gamma_SetBox.Text == string.Empty)
            {
                MessageBox.Show("内容为空!");
            }
            else  //标记关键事件
            {
                try
                {
                    arr = strLine.Split('\n'); //以逗号分割，添加到数
                    for (int i = txt_index; i < arr.Length;)  //获取的行数
                    {
                        perline = arr[i];
                        perline = perline.Replace(" ", "");
                        perline = perline.Replace(";", "");
                        perline = perline.Replace("(", "");
                        perline = perline.Replace(")", "");
                        perline = perline.Replace("\r", "");

                        if (perline.Contains("REGW"))
                        {
                            perline = perline.Replace("REGW", "");
                            VT6110_txtRegData.Text = perline;
                            VT6110_RegWR_Click(VT6110_RegW, null);
                            Thread.Sleep(200);
                            i = i + 1;
                        }
                        else if (perline.Contains("BISTON"))
                        {
                            VT6130_Bist_Pattern.Checked = true;
                            i = i + 1;
                        }
                        else if (perline.Contains("BISTOFF"))
                        {
                            VT6130_Bist_Pattern.Checked = false;
                            i = i + 1;
                        }
                        else if (perline.Contains("AOD_IN"))
                        {
                            cBx_AOD_Auto_Gamma.Checked = true;
                            i = i + 1;
                        }
                        else if (perline.Contains("AOD_OUT"))
                        {
                            cBx_AOD_Auto_Gamma.Checked = false;
                            i = i + 1;
                        }
                        else if (perline.Contains("SAVE"))
                        {
                            string pathsave_file = System.Environment.CurrentDirectory + "\\l_gamma";
                            if (Directory.Exists(pathsave_file) == false)
                            {
                                Directory.CreateDirectory(pathsave_file);
                            }
                            string pathsave = System.Environment.CurrentDirectory + "\\l_gamma" + "\\gamma" + Multi_gamma_group_index.ToString() + ".csv";
                            Multi_SaveGamma(pathsave);
                            Thread.Sleep(50);
                            i = i + 1;
                        }
                        else if (perline.Contains("GAMMA_SET"))
                        {
                            perline = perline.Replace("GAMMA_SET", "");
                            perline = perline.Replace("_", "");
                            Multi_gamma_group_index = Convert.ToInt32(perline);
                            VT6110_Gamma_Group.Value = Multi_gamma_group_index;
                            ArrayList list = new ArrayList();
                            do
                            {
                                i = i + 1;
                                perline = arr[i];
                                list.Add(perline + "\n");
                            } while (perline.Contains("GAMMA_TUNING") == false);
                            string[] gamma_set_lines = (string[])list.ToArray(typeof(string));
                            Text_Processing(gamma_set_lines);
                            try
                            {
                                string pathsave_file = System.Environment.CurrentDirectory + "\\l_gamma";
                                if (Directory.Exists(pathsave_file) == false)
                                {
                                    Directory.CreateDirectory(pathsave_file);
                                }
                                string pathload = System.Environment.CurrentDirectory + "\\l_gamma" + "\\gamma" + Multi_gamma_group_index.ToString() + ".csv";
                                Multi_LoadGamma(pathload);
                                Application.DoEvents();

                                VT6110_GAMMA_Click(VT6110_GammaW_Red, null);
                                Thread.Sleep(20);
                                VT6110_GAMMA_Click(VT6110_GammaW_Green, null);
                                Thread.Sleep(20);
                                VT6110_GAMMA_Click(VT6110_GammaW_Blue, null);
                                Thread.Sleep(20);
                            }
                            catch {; }
                            if (Total_points > 15)
                            {
                                rbt_VT6110_P25.Checked = true;
                            }
                            else if (Total_points == 15)
                            {
                                rbt_VT6110_P15.Checked = true;
                            }
                            else
                            {
                                rbt_VT6110_IRC.Checked = true;
                            }
                            btnAutoGammas_VT6110_Click(null, null); //替换成相应IC的自动gamma启动函数名
                            list_view_index = i;
                            break;
                        }
                        else
                        {
                            i = i + 1;
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("输入格式有误！");
                }
            }
        }
        private void Text_Processing(string[] txt_path)
        {
            double L_X, L_Y, L_Z;
            string[] arr = txt_path;
            {
                try
                {
                    Diven_Gamma.Clear();
                    Diven_Offset.Clear();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        string line = arr[i];
                        line = line.Replace(" ", "");
                        if (line.Contains("TUNING_SPEC"))
                        {
                            line = line.Replace("TUNING_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr0 = line.Split(',');
                            Setting.Gamma_Property Gamma = new Setting.Gamma_Property(Convert.ToInt32(arr0[0]), Convert.ToDouble(arr0[1]), Convert.ToDouble(arr0[2]), Convert.ToDouble(arr0[3]), Convert.ToDouble(arr0[4]));
                            Diven_Gamma.Add(Gamma);
                        }
                        else if (line.Contains("LXY_SPEC"))
                        {
                            line = line.Replace("LXY_SPEC", "");
                            line = line.Replace("(", "");
                            line = line.Replace(")", "");
                            string[] arr1 = line.Split(',');
                            //将Offset对象放入集合
                            Setting.Offset_Property Offset = new Setting.Offset_Property(Convert.ToInt32(arr1[0]), Convert.ToDouble(arr1[1]), Convert.ToDouble(arr1[2]), Convert.ToDouble(arr1[3]));
                            Diven_Offset.Add(Offset);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("格式输入有误");
                }
            }
            try  //获取调整spec
            {
                txtVT6110_loff.Text = Diven_Offset[0].LUM_OFF.ToString();
                txtVT6110_xoff.Text = Diven_Offset[0].X_OFF.ToString();
                txtVT6110_yoff.Text = Diven_Offset[0].Y_OFF.ToString();

                Total_points = Diven_Gamma[0].Points_num;
                D_lums = new double[Total_points, 3];
                D_lum = new double[Total_points];

                txtVT6110_gamma.Text = Diven_Gamma[0].Curve.ToString();
                txtVT6110_lum.Text = Diven_Gamma[0].Lum.ToString();
                txtVT6110_x.Text = Diven_Gamma[0].X.ToString();
                txtVT6110_y.Text = Diven_Gamma[0].Y.ToString();

                for (int i = 0; i < Total_points; i++)
                {   //Diven_Offset[p].NO 灰阶绑点                 
                    D_lum[i] = (Math.Pow((Diven_Offset[i].NO / 255.0), Diven_Gamma[0].Curve) * Diven_Gamma[0].Lum); //每绑点目标亮度
                    CaSDKObj.Lvxy_to_XYZ(D_lum[i], Diven_Gamma[0].X, Diven_Gamma[0].Y, out L_X, out L_Y, out L_Z);//X/Z/Z转换
                    D_lums[i, 0] = L_X; //R/B/G分亮度计算
                    D_lums[i, 1] = L_Y;
                    D_lums[i, 2] = L_Z;
                }
            }
            catch
            {
                MessageBox.Show("格式输入有误");
            }
        }
        //---------------------------------add-------------------------------------
        //Gamma自动保存
        private void Multi_SaveGamma(string path)
        {
            try
            {
                string str = "保存Gamma文件";
                StreamWriter sw = null; //文件流
                sw = new StreamWriter(path, false, Encoding.UTF8);
                str = str + "R0," + VT6110_R0.Text + "," + "G0," + VT6110_G0.Text + "," + "B0," + VT6110_B0.Text + "\r\n";
                str = str + "R1," + VT6110_R1.Text + "," + "G1," + VT6110_G1.Text + "," + "B1," + VT6110_B1.Text + "\r\n";
                str = str + "R3," + VT6110_R3.Text + "," + "G3," + VT6110_G3.Text + "," + "B3," + VT6110_B3.Text + "\r\n";
                str = str + "R5," + VT6110_R5.Text + "," + "G5," + VT6110_G5.Text + "," + "B5," + VT6110_B5.Text + "\r\n";
                str = str + "R7," + VT6110_R7.Text + "," + "G7," + VT6110_G7.Text + "," + "B7," + VT6110_B7.Text + "\r\n";
                str = str + "R11," + VT6110_R11.Text + "," + "G11," + VT6110_G11.Text + "," + "B11," + VT6110_B11.Text + "\r\n";
                str = str + "R15," + VT6110_R15.Text + "," + "G15," + VT6110_G15.Text + "," + "B15," + VT6110_B15.Text + "\r\n";
                str = str + "R19," + VT6110_R19.Text + "," + "G19," + VT6110_G19.Text + "," + "B20," + VT6110_B19.Text + "\r\n";
                str = str + "R23," + VT6110_R23.Text + "," + "G23," + VT6110_G23.Text + "," + "B23," + VT6110_B23.Text + "\r\n";
                str = str + "R27," + VT6110_R27.Text + "," + "G27," + VT6110_G27.Text + "," + "B27," + VT6110_B27.Text + "\r\n";
                str = str + "R31," + VT6110_R31.Text + "," + "G31," + VT6110_G31.Text + "," + "B31," + VT6110_B31.Text + "\r\n";
                str = str + "R35," + VT6110_R35.Text + "," + "G35," + VT6110_G35.Text + "," + "B35," + VT6110_B35.Text + "\r\n";
                str = str + "R39," + VT6110_R39.Text + "," + "G39," + VT6110_G39.Text + "," + "B39," + VT6110_B39.Text + "\r\n";
                str = str + "R47," + VT6110_R47.Text + "," + "G47," + VT6110_G47.Text + "," + "B47," + VT6110_B47.Text + "\r\n";
                str = str + "R55," + VT6110_R55.Text + "," + "G55," + VT6110_G55.Text + "," + "B55," + VT6110_B55.Text + "\r\n";
                str = str + "R63," + VT6110_R63.Text + "," + "G63," + VT6110_G63.Text + "," + "B63," + VT6110_B63.Text + "\r\n";
                str = str + "R71," + VT6110_R71.Text + "," + "G71," + VT6110_G71.Text + "," + "B71," + VT6110_B71.Text + "\r\n";
                str = str + "R79," + VT6110_R79.Text + "," + "G79," + VT6110_G79.Text + "," + "B79," + VT6110_B79.Text + "\r\n";
                str = str + "R95," + VT6110_R95.Text + "," + "G95," + VT6110_G95.Text + "," + "B95," + VT6110_B95.Text + "\r\n";
                str = str + "R111," + VT6110_R111.Text + "," + "G111," + VT6110_G111.Text + "," + "B111," + VT6110_B111.Text + "\r\n";
                str = str + "R127," + VT6110_R127.Text + "," + "G127," + VT6110_G127.Text + "," + "B127," + VT6110_B127.Text + "\r\n";
                str = str + "R159," + VT6110_R159.Text + "," + "G159," + VT6110_G159.Text + "," + "B159," + VT6110_B159.Text + "\r\n";
                str = str + "R191," + VT6110_R191.Text + "," + "G191," + VT6110_G191.Text + "," + "B191," + VT6110_B191.Text + "\r\n";
                str = str + "R223," + VT6110_R223.Text + "," + "G223," + VT6110_G223.Text + "," + "B223," + VT6110_B223.Text + "\r\n";
                str = str + "R255," + VT6110_R255.Text + "," + "G255," + VT6110_G255.Text + "," + "B255," + VT6110_B255.Text + "\r\n";
                sw.WriteLine(str);
                sw.Dispose(); //释放资源
                sw.Close(); //关闭数据流
            }
            catch
            {
                MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
            }
        } //

        //Gamma自动载入
        private void Multi_LoadGamma(string path)
        {
            string strtmp = "";
            //读取文本信息
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
            streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
            string strLine = streamReader.ReadLine();
            //循环读取文本信息
            while (!string.IsNullOrEmpty(strLine))
            {
                strtmp = strtmp + strLine + ",";
                strLine = streamReader.ReadLine(); //循环读取下一行
            }
            fs.Close(); //关闭流
            streamReader.Close();
            string[] arrtmp = strtmp.Split(new Char[] { ',' });
            VT6110_R0.Text = arrtmp[1].ToString(); VT6110_G0.Text = arrtmp[3].ToString(); VT6110_B0.Text = arrtmp[5].ToString();
            VT6110_R1.Text = arrtmp[7].ToString(); VT6110_G1.Text = arrtmp[9].ToString(); VT6110_B1.Text = arrtmp[11].ToString();
            VT6110_R3.Text = arrtmp[13].ToString(); VT6110_G3.Text = arrtmp[15].ToString(); VT6110_B3.Text = arrtmp[17].ToString();
            VT6110_R5.Text = arrtmp[19].ToString(); VT6110_G5.Text = arrtmp[21].ToString(); VT6110_B5.Text = arrtmp[23].ToString();
            VT6110_R7.Text = arrtmp[25].ToString(); VT6110_G7.Text = arrtmp[27].ToString(); VT6110_B7.Text = arrtmp[29].ToString();
            VT6110_R11.Text = arrtmp[31].ToString(); VT6110_G11.Text = arrtmp[33].ToString(); VT6110_B11.Text = arrtmp[35].ToString();
            VT6110_R15.Text = arrtmp[37].ToString(); VT6110_G15.Text = arrtmp[39].ToString(); VT6110_B15.Text = arrtmp[41].ToString();
            VT6110_R19.Text = arrtmp[43].ToString(); VT6110_G19.Text = arrtmp[45].ToString(); VT6110_B19.Text = arrtmp[47].ToString();
            VT6110_R23.Text = arrtmp[49].ToString(); VT6110_G23.Text = arrtmp[51].ToString(); VT6110_B23.Text = arrtmp[53].ToString();
            VT6110_R27.Text = arrtmp[55].ToString(); VT6110_G27.Text = arrtmp[57].ToString(); VT6110_B27.Text = arrtmp[59].ToString();
            VT6110_R31.Text = arrtmp[61].ToString(); VT6110_G31.Text = arrtmp[63].ToString(); VT6110_B31.Text = arrtmp[65].ToString();
            VT6110_R35.Text = arrtmp[67].ToString(); VT6110_G35.Text = arrtmp[69].ToString(); VT6110_B35.Text = arrtmp[71].ToString();
            VT6110_R39.Text = arrtmp[73].ToString(); VT6110_G39.Text = arrtmp[75].ToString(); VT6110_B39.Text = arrtmp[77].ToString();
            VT6110_R47.Text = arrtmp[79].ToString(); VT6110_G47.Text = arrtmp[81].ToString(); VT6110_B47.Text = arrtmp[83].ToString();
            VT6110_R55.Text = arrtmp[85].ToString(); VT6110_G55.Text = arrtmp[87].ToString(); VT6110_B55.Text = arrtmp[89].ToString();
            VT6110_R63.Text = arrtmp[91].ToString(); VT6110_G63.Text = arrtmp[93].ToString(); VT6110_B63.Text = arrtmp[95].ToString();
            VT6110_R71.Text = arrtmp[97].ToString(); VT6110_G71.Text = arrtmp[99].ToString(); VT6110_B71.Text = arrtmp[101].ToString();
            VT6110_R79.Text = arrtmp[103].ToString(); VT6110_G79.Text = arrtmp[105].ToString(); VT6110_B79.Text = arrtmp[107].ToString();
            VT6110_R95.Text = arrtmp[109].ToString(); VT6110_G95.Text = arrtmp[111].ToString(); VT6110_B95.Text = arrtmp[113].ToString();
            VT6110_R111.Text = arrtmp[115].ToString(); VT6110_G111.Text = arrtmp[117].ToString(); VT6110_B111.Text = arrtmp[119].ToString();
            VT6110_R127.Text = arrtmp[121].ToString(); VT6110_G127.Text = arrtmp[123].ToString(); VT6110_B127.Text = arrtmp[125].ToString();
            VT6110_R159.Text = arrtmp[127].ToString(); VT6110_G159.Text = arrtmp[129].ToString(); VT6110_B159.Text = arrtmp[131].ToString();
            VT6110_R191.Text = arrtmp[133].ToString(); VT6110_G191.Text = arrtmp[135].ToString(); VT6110_B191.Text = arrtmp[137].ToString();
            VT6110_R223.Text = arrtmp[139].ToString(); VT6110_G223.Text = arrtmp[141].ToString(); VT6110_B223.Text = arrtmp[143].ToString();
            VT6110_R255.Text = arrtmp[145].ToString(); VT6110_G255.Text = arrtmp[147].ToString(); VT6110_B255.Text = arrtmp[149].ToString();
        }

        private void Rbt_VT6110_P15_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (VT6110_Gamma_SetBox.Text == string.Empty)
            {
                MessageBox.Show("内容为空!");
            }
            else
            {
                //创建保存对话框对象
                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "gamma cfg files (*.txt)|*.txt"; //过滤文件类型
                save.FilterIndex = 1;
                save.RestoreDirectory = true;
                if (save.ShowDialog() == DialogResult.OK)
                {
                    string path = save.FileName;
                    save.DefaultExt = ".txt";
                    StreamWriter sw = new StreamWriter(path);
                    sw.WriteLine(VT6110_Gamma_SetBox.Text);
                    sw.Close();
                }
            }
        }
        private void 载入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "精度配置文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            of.Title = "gamma cfg write";

            if (of.ShowDialog() == DialogResult.OK)
            {
                VT6110_Gamma_SetBox.Clear();
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string str_generate = streamReader.ReadLine();
                //循环读取文本信息
                while (str_generate != null)
                {
                    VT6110_Gamma_SetBox.AppendText(str_generate + "\r\n");
                    str_generate = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
            }
        }


        /// <summary>
        /// IRC function
        /// </summary>
        public struct IRC_Input
        {
            public int[] Para;//In_Para
            public int[,] Ratio_V255_GC;//[RGB/OPR 16.91,33.33,50,75,100]
            public int[] DBV;
            public int[] DBV_Mode;//0:Normal 1:DLL 2:OffSet 3:Base
            public int[,,] IRC_GC_In;//[Set/RGB/GC Code]

            public string[] IRC_Msg;
        }

        public struct IRC_Output
        {
            public int[,] Reg_Out;//[CMD,Para]
            public int[,,] IRC_GC_Out;//[Set/RGB/GC Code]
        }
        //==============================================================
        IRC_Input Reg_IRC = new IRC_Input();
        IRC_Output Reg_Result_IRC = new IRC_Output();

        //==============================================================
        public void interface_Param()
        {
            Reg_IRC.Para = new int[9] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            Reg_IRC.Ratio_V255_GC = new int[3, 5];
            Reg_IRC.DBV = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            Reg_IRC.DBV_Mode = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            Reg_IRC.IRC_GC_In = new int[10, 3, 25];
            Reg_Result_IRC.IRC_GC_Out = new int[10, 3, 25];
            Reg_Result_IRC.Reg_Out = new int[2, 30];

            Array.Clear(Reg_IRC.Para, 0, Reg_IRC.Para.Length);
            Array.Clear(Reg_IRC.Ratio_V255_GC, 0, Reg_IRC.Ratio_V255_GC.Length);
            Array.Clear(Reg_IRC.DBV, 0, Reg_IRC.DBV.Length);
            Array.Clear(Reg_IRC.DBV_Mode, 0, Reg_IRC.DBV_Mode.Length);
            Array.Clear(Reg_IRC.IRC_GC_In, 0, Reg_IRC.IRC_GC_In.Length);
            Array.Clear(Reg_Result_IRC.IRC_GC_Out, 0, Reg_Result_IRC.IRC_GC_Out.Length);
            Array.Clear(Reg_Result_IRC.Reg_Out, 0, Reg_Result_IRC.Reg_Out.Length);
        }

        public void IRC_Initialize(object sender, EventArgs e)
        {
            dataGridView_Para_In.Rows.Clear();
            dataGridView_Para_In.Rows.Add("LHB_EN", "0");
            dataGridView_Para_In.Rows.Add("DBV_EN", "1");
            dataGridView_Para_In.Rows.Add("HBM_EN", "0");
            dataGridView_Para_In.Rows.Add("Weight_R", "88");
            dataGridView_Para_In.Rows.Add("Weight_G", "70");
            dataGridView_Para_In.Rows.Add("Weight_B", "98");
            dataGridView_Para_In.Rows.Add("Max DBV", "2047");
            dataGridView_Para_In.Rows.Add("Internal_A", "2");
            dataGridView_Para_In.Rows.Add("Internal_B", "2");

            dataGridView_BestGC.Rows.Clear();
            dataGridView_BestGC.Rows.Add("16.91%", "823", "788", "871");
            dataGridView_BestGC.Rows.Add("33.33%", "837", "801", "883");
            dataGridView_BestGC.Rows.Add("50%", "845", "809", "891");
            dataGridView_BestGC.Rows.Add("75%", "860", "824", "906");
            dataGridView_BestGC.Rows.Add("100%", "872", "836", "921");

            dataGridView_GC_DBV.Rows.Clear();
            if (rbt_Normal_DBV.Checked)
            {
                dataGridView_GC_DBV.Rows.Add("GC_Set1", "3", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set2", "1", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set3", "3", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set4", "1", "1024");
                dataGridView_GC_DBV.Rows.Add("GC_Set5", "0", "500");
                dataGridView_GC_DBV.Rows.Add("GC_Set6", "0", "273");
                dataGridView_GC_DBV.Rows.Add("GC_Set7", "0", "91");
                dataGridView_GC_DBV.Rows.Add("GC_Set8", "3", "27");
                dataGridView_GC_DBV.Rows.Add("GC_Set9", "1", "9");
                dataGridView_GC_DBV.Rows.Add("GC_Set10", "0", "0");
                dataGridView_GC_DBV.Rows.Add("GC_Set11", "0", "0");
                dataGridView_GC_DBV.Rows.Add("GC_Set12", "0", "0");
            }
            else
            {
                dataGridView_GC_DBV.Rows.Add("GC_Set1", "3", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set2", "1", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set3", "3", "2047");
                dataGridView_GC_DBV.Rows.Add("GC_Set4", "1", "1024");
                dataGridView_GC_DBV.Rows.Add("GC_Set5", "3", "500");
                dataGridView_GC_DBV.Rows.Add("GC_Set6", "1", "273");
                dataGridView_GC_DBV.Rows.Add("GC_Set7", "1", "91");
                dataGridView_GC_DBV.Rows.Add("GC_Set8", "1", "27");
                dataGridView_GC_DBV.Rows.Add("GC_Set9", "1", "9");
                dataGridView_GC_DBV.Rows.Add("GC_Set10", "0", "0");
                dataGridView_GC_DBV.Rows.Add("GC_Set11", "0", "0");
                dataGridView_GC_DBV.Rows.Add("GC_Set12", "0", "0");
            }
        }

        private void Rbt_Normal_DBV_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView_GC_DBV.Rows.Clear();
            dataGridView_GC_DBV.Rows.Add("GC_Set1", "3", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set2", "1", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set3", "3", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set4", "1", "1024");
            dataGridView_GC_DBV.Rows.Add("GC_Set5", "0", "500");
            dataGridView_GC_DBV.Rows.Add("GC_Set6", "0", "273");
            dataGridView_GC_DBV.Rows.Add("GC_Set7", "0", "91");
            dataGridView_GC_DBV.Rows.Add("GC_Set8", "3", "27");
            dataGridView_GC_DBV.Rows.Add("GC_Set9", "1", "9");
            dataGridView_GC_DBV.Rows.Add("GC_Set10", "0", "0");
            dataGridView_GC_DBV.Rows.Add("GC_Set11", "0", "0");
            dataGridView_GC_DBV.Rows.Add("GC_Set12", "0", "0");
        }

        private void Rbt_DC_DBV_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView_GC_DBV.Rows.Clear();
            dataGridView_GC_DBV.Rows.Add("GC_Set1", "3", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set2", "1", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set3", "3", "2047");
            dataGridView_GC_DBV.Rows.Add("GC_Set4", "1", "1024");
            dataGridView_GC_DBV.Rows.Add("GC_Set5", "3", "500");
            dataGridView_GC_DBV.Rows.Add("GC_Set6", "1", "273");
            dataGridView_GC_DBV.Rows.Add("GC_Set7", "1", "91");
            dataGridView_GC_DBV.Rows.Add("GC_Set8", "1", "27");
            dataGridView_GC_DBV.Rows.Add("GC_Set9", "1", "9");
            dataGridView_GC_DBV.Rows.Add("GC_Set10", "0", "0");
            dataGridView_GC_DBV.Rows.Add("GC_Set11", "0", "0");
            dataGridView_GC_DBV.Rows.Add("GC_Set12", "0", "0");
        }

        private void button2_Click_1(object sender, EventArgs e)
        {

        }


        private void IRC_Reg_Ini()
        {
            int i, RGB;

            for (i = 0; i < 9; i++)    //获取 DBV 设定以及 ELVSS /ELVDD 电流比例等参数
            {
                Reg_IRC.Para[i] = Convert.ToInt16(dataGridView_Para_In.Rows[i].Cells[1].Value);
            }

            for (RGB = 0; RGB < 3; RGB++)   //获取5组不同画面下的Gamma R/G/G 寄存器值
            {
                for (i = 0; i < 5; i++)
                {
                    Reg_IRC.Ratio_V255_GC[RGB, i] = Convert.ToInt16(dataGridView_BestGC.Rows[i].Cells[RGB + 1].Value);
                }
            }
            //Reg_IRC.Max_DBV = Convert.ToInt16(dataGridView_GC_DBV.Rows[0].Cells[2].Value);
            for (i = 0; i < 12; i++)   //获取DBV 设定
            {
                Reg_IRC.DBV[i] = Convert.ToInt16(dataGridView_GC_DBV.Rows[i].Cells[2].Value);
                Reg_IRC.DBV_Mode[i] = Convert.ToInt16(dataGridView_GC_DBV.Rows[i].Cells[1].Value);
            }
        }
        private void GC_In()
        {
            string[] list;
            int i, j, GC_set, GC_Count, GC_Dec, RGB_Count, Regw_Flag;
            string line, CMD, GC_Temp;

            Reg_IRC.IRC_Msg = new string[richTextBox_GC_In.Lines.Length];

            GC_set = 0;
            GC_Count = 0;
            RGB_Count = 0;
            Regw_Flag = 1;//0:Have "Regw" 1:No "Regw"

            for (i = 0; i < richTextBox_GC_In.Lines.Length; i++)
            {
                Reg_IRC.IRC_Msg[i] = richTextBox_GC_In.Lines[i];
                line = richTextBox_GC_In.Lines[i];
                line = line.Replace(" ", "");
                list = line.Trim().Split(',');

                if (list[0] == "")
                {
                    continue;
                }
                //else if ((list[0] == "REGW") || (list[0] == "regw") || (list[0].Substring(0, 2) == "0x"))
                {
                    if (list[0].Substring(0, 2) == "0x")
                        Regw_Flag = 1;
                    else
                        Regw_Flag = 0;


                    CMD = list[1 - 1].Substring(0, 2);//取 CMD

                    if ((CMD == "B0") || (CMD == "B1") || (CMD == "B2") || (CMD == "B3"))
                    {
                        RGB_Count = 0;
                    }
                    else if ((CMD == "B4") || (CMD == "B5") || (CMD == "B6") || (CMD == "B7"))
                    {
                        RGB_Count = 1;
                    }
                    else if ((CMD == "B8") || (CMD == "B9") || (CMD == "BA") || (CMD == "BB"))
                    {
                        RGB_Count = 2;
                    }
                    else
                    {
                        continue;
                    }

                    list = line.Trim().Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    if ((CMD == "B3") || (CMD == "B7") || (CMD == "BB"))
                    {
                        GC_Temp = list[2 - 1].Substring(0, 2) + list[3 - 1].Substring(0, 2);
                        GC_Dec = Int32.Parse(GC_Temp, System.Globalization.NumberStyles.HexNumber);
                        Reg_IRC.IRC_GC_In[GC_set, RGB_Count, GC_Count] = GC_Dec;

                        GC_Count = 0;
                        if (CMD == "BB")
                            GC_set = GC_set + 1;
                    }
                    else
                    {
                        for (j = 0; j < 8; j++)
                        {
                            GC_Temp = list[2 - 1 + j * 2].Substring(0, 2) + list[3 - 1 + j * 2].Substring(0, 2);
                            GC_Dec = Int32.Parse(GC_Temp, System.Globalization.NumberStyles.HexNumber);
                            Reg_IRC.IRC_GC_In[GC_set, RGB_Count, GC_Count] = GC_Dec;

                            GC_Count = GC_Count + 1;
                        }
                    }
                }
                //else
                //{
                //    continue;
                //}
            }
        }
        private void GC_Out()
        {
            string[] list;
            int i, j, DBV_set, GC_Count, RGB_Count, Regw_Flag;
            string line, CMD, GC_Hex, GC_H_Byte, GC_L_Byte;

            DBV_set = 0;
            GC_Count = 0;
            RGB_Count = 0;
            Regw_Flag = 0;//0:Have "Regw" 1:No "Regw"

            //CMD2P3
            richTextBox_GC_Out.Text += "F0,AA,13" + "\n\n";

            for (i = 0; i < Reg_IRC.IRC_Msg.Length; i++)
            {
                line = Reg_IRC.IRC_Msg[i];
                line = line.Replace(" ", "");
                list = line.Trim().Split(',');

                if (list[0] == "")
                {
                    richTextBox_GC_Out.Text += line + "\n";
                    continue;
                }
                //else if ((list[0] == "REGW") || (list[0] == "regw") || (list[0].Substring(0, 2) == "0x"))
                {
                    if (list[0].Substring(0, 2) == "0x")
                        Regw_Flag = 1;
                    else
                        Regw_Flag = 0;

                    CMD = list[1 - 1].Substring(0, 2);
                    if ((CMD == "B0") || (CMD == "B1") || (CMD == "B2") || (CMD == "B3"))
                    {
                        RGB_Count = 0;
                    }
                    else if ((CMD == "B4") || (CMD == "B5") || (CMD == "B6") || (CMD == "B7"))
                    {
                        RGB_Count = 1;
                    }
                    else if ((CMD == "B8") || (CMD == "B9") || (CMD == "BA") || (CMD == "BB"))
                    {
                        RGB_Count = 2;
                    }

                    if (CMD == "B0" || (CMD == "B1") || (CMD == "B2") || (CMD == "B4") || (CMD == "B5") || (CMD == "B6") || (CMD == "B8") || (CMD == "B9") || (CMD == "BA"))
                    {
                        richTextBox_GC_Out.Text += "" + CMD;

                        for (j = 0; j < 8; j++)
                        {
                            GC_Hex = Convert.ToString(Reg_Result_IRC.IRC_GC_Out[DBV_set, RGB_Count, GC_Count], 16);//To Hex
                            GC_Hex = GC_Hex.ToUpper().PadLeft(4, '0');//Add "0"
                            //GC_Hex = GC_Hex.ToUpper();
                            GC_H_Byte = "," + GC_Hex.Substring(0, 2);
                            GC_L_Byte = "," + GC_Hex.Substring(2, 2);

                            richTextBox_GC_Out.Text += GC_H_Byte + GC_L_Byte;
                            GC_Count = GC_Count + 1;
                        }
                    }
                    else if ((CMD == "B3") || (CMD == "B7") || (CMD == "BB"))
                    {
                        richTextBox_GC_Out.Text += "" + CMD;

                        GC_Hex = Convert.ToString(Reg_Result_IRC.IRC_GC_Out[DBV_set, RGB_Count, GC_Count], 16);//To Hex
                        GC_Hex = GC_Hex.ToUpper().PadLeft(4, '0');//Add "0"
                        //GC_Hex = GC_Hex.ToUpper();
                        GC_H_Byte = "," + GC_Hex.Substring(0, 2);
                        GC_L_Byte = "," + GC_Hex.Substring(2, 2);

                        richTextBox_GC_Out.Text += GC_H_Byte + GC_L_Byte;
                        GC_Count = 0;

                        if (CMD == "BB")
                            DBV_set = DBV_set + 1;
                    }
                    else
                    {
                        richTextBox_GC_Out.Text += line + "\n";
                        continue;
                    }
                    richTextBox_GC_Out.Text += "\n";

                }
                //else
                //{
                //    richTextBox_GC_Out.Text += line + "\n";
                //    continue;
                //}
            }
        }
        private void IRC_Reg_Out()
        {
            int i;
            int[] OPR_Dif = { 0, 0, 0, 0 };
            string[] CMD_D5 = { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
            string[] CMD_D6 = { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
            string[] Para = { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };

            //CMD2P1
            richTextBox_GC_Out.Text += "F0,AA,11" + "\n";
            //0xD5
            richTextBox_GC_Out.Text += "\n";
            richTextBox_GC_Out.Text += "D5";
            for (i = 0; i < 23; i++)
            {
                CMD_D5[i] = "," + Convert.ToString(Reg_Result_IRC.Reg_Out[0, i], 16).ToUpper().PadLeft(2, '0');
                richTextBox_GC_Out.Text += CMD_D5[i];
            }

            //0xD6
            richTextBox_GC_Out.Text += "\n";
            richTextBox_GC_Out.Text += "D6";
            for (i = 0; i < 17; i++)
            {
                CMD_D6[i] = "," + Convert.ToString(Reg_Result_IRC.Reg_Out[1, i], 16).ToUpper().PadLeft(2, '0');
                richTextBox_GC_Out.Text += CMD_D6[i];
            }
        }
        private void button_Run_IRC_Click(object sender, EventArgs e)
        {
            try
            {
                Class1 IRC = new Class1();
                richTextBox_GC_Out.Clear();
                IRC_Reg_Ini();   //获取dll输入参数，包含Max_DBV ELVDD/ELVSS 电流值等参数、不同画面下的5组255灰阶对应的RGB寄存器值 以及DBV 分段参数值
                GC_In();  //获取普通模式下的Gamma寄存器值；
                IRC.IRC_In_Out(Reg_IRC.Para, Reg_IRC.Ratio_V255_GC, Reg_IRC.DBV, Reg_IRC.DBV_Mode, Reg_IRC.IRC_GC_In, ref Reg_Result_IRC.IRC_GC_Out, ref Reg_Result_IRC.Reg_Out);
                GC_Out(); // 输出修正后的Gamma
                IRC_Reg_Out();  //输出D5 D6 参数 及使能
            }
            catch
            {
                MessageBox.Show("IRC转换失败！");
            }
        }

        //采集R255,G255,B255的ELVSS电流
        private bool Measure_ELVSSC_Red_flag = false;
        private bool Measure_ELVSSC_Green_flag = false;
        private bool Measure_ELVSSC_Blue_flag = false;
        private void Measure_ELVSSC_Red(object sender, EventArgs e)
        {
            Measure_ELVSSC_Red_flag = true;
            Measure_ELVSSC_Green_flag = false;
            Measure_ELVSSC_Blue_flag = false;
            frmHelp.OLED_Show_Click(frmHelp.btnred, e);
            Thread.Sleep(2222);
            frmHelp.PMU_OPERATION_Click(frmHelp.btnPowertest, e);
        }
        private void Measure_ELVSSC_Green(object sender, EventArgs e)
        {
            Measure_ELVSSC_Red_flag = false;
            Measure_ELVSSC_Green_flag = true;
            Measure_ELVSSC_Blue_flag = false;
            frmHelp.OLED_Show_Click(frmHelp.btngreen, e);
            Thread.Sleep(2222);
            frmHelp.PMU_OPERATION_Click(frmHelp.btnPowertest, e);
        }
        private void Measure_ELVSSC_Blue(object sender, EventArgs e)
        {
            Measure_ELVSSC_Red_flag = false;
            Measure_ELVSSC_Green_flag = false;
            Measure_ELVSSC_Blue_flag = true;
            frmHelp.OLED_Show_Click(frmHelp.btnblue, e);
            Thread.Sleep(2222);
            frmHelp.PMU_OPERATION_Click(frmHelp.btnPowertest, e);
        }

        private void Calu_IRC_WEIGHT(object sender, EventArgs e)
        {
            IRC_WEIGHT_R = Convert.ToByte(Ir * 255 / (Ir + Ig + Ib));
            IRC_WEIGHT_G = Convert.ToByte(Ig * 255 / (Ir + Ig + Ib));
            IRC_WEIGHT_B = Convert.ToByte(Ib * 255 / (Ir + Ig + Ib));

            dataGridView_Para_In.Rows[3].Cells[1].Value = IRC_WEIGHT_R + "";
            dataGridView_Para_In.Rows[4].Cells[1].Value = IRC_WEIGHT_G + "";
            dataGridView_Para_In.Rows[5].Cells[1].Value = IRC_WEIGHT_B + "";
            /*
                        dataGridView_Para_In.Rows.Clear();
                        dataGridView_Para_In.Rows.Add("LHB_EN", "0");
                        dataGridView_Para_In.Rows.Add("DBV_EN", "1");
                        dataGridView_Para_In.Rows.Add("HBM_EN", "0");
                        dataGridView_Para_In.Rows.Add("Weight_R", IRC_WEIGHT_R.ToString());
                        dataGridView_Para_In.Rows.Add("Weight_G", IRC_WEIGHT_G.ToString());
                        dataGridView_Para_In.Rows.Add("Weight_B", IRC_WEIGHT_B.ToString());
                        dataGridView_Para_In.Rows.Add("Max DBV", "2047");
                        dataGridView_Para_In.Rows.Add("Internal_A", "2");
                        dataGridView_Para_In.Rows.Add("Internal_B", "2");*/
        }
        private int Measure_Step = 0;
        private void Button_Measure_ELVSSC_Click(object sender, EventArgs e)
        {
            VT6110_txtRegData.Text = "51,07,ff";
            VT6110_RegWR_Click(VT6110_RegW, null);
            T1.Enabled = true;
            Measure_Step = 0;
        }

        private void T1_Tick(object sender, EventArgs e)
        {
            switch (Measure_Step)
            {
                case 0:
                    Measure_ELVSSC_Red(null, null);
                    Measure_Step = Measure_Step + 1;
                    break;
                case 1:
                    Measure_ELVSSC_Green(null, null);
                    Measure_Step = Measure_Step + 1;
                    break;
                case 2:
                    Measure_ELVSSC_Blue(null, null);
                    Measure_Step = Measure_Step + 1;
                    break;
                case 3:
                    Calu_IRC_WEIGHT(null, null);
                    T1.Enabled = false;
                    break;
            }
        }

        private void Button_Read_Gamma_Convert()
        {
            richTextBox_GC_In.Text = null;
            richTextBox_GC_In.Text = frmHelp.Generate_Read_Result_txt.Text;
            frmHelp.rBt_HS_DCS_Short_Write.Checked = true;
        }

        private void btn_LYH_Read_Gamma_Click(object sender, EventArgs e)
        {
            frmHelp.rBt_LP_DCS_Long_Write.Checked = true;
            frmHelp.Generate_Read_Result_txt.Text = null;
            frmHelp.Generate_textBox.Text = null;
            frmHelp.Generate_textBox.Text = LYH_Gamma_SetBox.Text;
            Application.DoEvents();
            frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, null);
            Application.DoEvents();
            richTextBox2.Text = frmHelp.Generate_Read_Result_txt.Text;
        }

        private int BF00_INDEX;
        private void Button_Read_Gamma_Click(object sender, EventArgs e)
        {
            BF00_INDEX = 0;
            frmHelp.rBt_LP_DCS_Long_Write.Checked = true;
            frmHelp.Generate_Read_Result_txt.Text = null;
            frmHelp.Generate_textBox.Text = null;
            frmHelp.Generate_textBox.Text = "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,08\r\n" +
            "DELAY500\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,07\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,06\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,05\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,04\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,03\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,02\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,01\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n" +

            "DELAY100\r\n" +
            "IC WRITE\r\n" +
            "f0,aa,13\r\n" +
            "c4,01\r\n" +
            "BF,00\r\n" +
            "DELAY200\r\n" +
            "IC READ\r\n" +
            "b0,10\r\n" +
            "b1,10\r\n" +
            "b2,10\r\n" +
            "b3,02\r\n" +
            "b4,10\r\n" +
            "b5,10\r\n" +
            "b6,10\r\n" +
            "b7,02\r\n" +
            "b8,10\r\n" +
            "b9,10\r\n" +
            "ba,10\r\n" +
            "bb,02\r\n";
            Application.DoEvents();
            frmHelp.Generate_File_Click(frmHelp.Generate_File_Run, null);
            Button_Read_Gamma_Convert();
        }
        private void Button_Setting_Gamma_Click(object sender, EventArgs e)
        {
            string pathsave_file = System.Environment.CurrentDirectory + "\\l_gamma";
            if (Gamma_loading_path.Text.Length <= 6)
            {
                Gamma_loading_path.Text = pathsave_file;
            }
            VT6110_Gamma_SetBox.Text = null;
            VT6110_Gamma_SetBox.Text =
            "REGW 51,07,FF\r\n" +
            "__GAMMA_SET(7)\r\n" +
            "TUNING_SPEC(5, 450, 0.300, 0.315, 2.2)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "LXY_SPEC(255, 0.001, 0.001, 0.15)\r\n" +
            "__GAMMA_TUNING \r\n" +
            "SAVE";
            rbt_VT6110_IRC.Checked = true;
            Btn_flexible_gamma_Click(null, null);
        }
        private void Button_Convert_Gamma_format_Click(object sender, EventArgs e)
        {
            txt_Demura_need_gamma_format.Text = null;
            txt_Demura_need_gamma_format.Text = txt_Demura_need_gamma_format.Text + "0\r\n" +
            "1\r\n" + "3\r\n" + "5\r\n" + "7\r\n" + "11\r\n" + "15\r\n" + "19\r\n" +
            "23\r\n" + "27\r\n" + "31\r\n" + "35\r\n" + "39\r\n" + "47\r\n" + "55\r\n" +
            "63\r\n" + "71\r\n" + "79\r\n" + "95\r\n" + "111\r\n" + "127\r\n" + "159\r\n" +
            "191\r\n" + "223\r\n" + "255\r\n"
            + VT6110_R0.Value.ToString() + "\r\n" + VT6110_R1.Value.ToString() + "\r\n" + VT6110_R3.Value.ToString() + "\r\n" + VT6110_R5.Value.ToString() + "\r\n" + VT6110_R7.Value.ToString() + "\r\n" + VT6110_R11.Value.ToString() + "\r\n" + VT6110_R15.Value.ToString() + "\r\n" + VT6110_R19.Value.ToString() + "\r\n" + VT6110_R23.Value.ToString() + "\r\n"
            + VT6110_R27.Value.ToString() + "\r\n" + VT6110_R31.Value.ToString() + "\r\n" + VT6110_R35.Value.ToString() + "\r\n" + VT6110_R39.Value.ToString() + "\r\n" + VT6110_R47.Value.ToString() + "\r\n" + VT6110_R55.Value.ToString() + "\r\n" + VT6110_R63.Value.ToString() + "\r\n" + VT6110_R71.Value.ToString() + "\r\n" + VT6110_R79.Value.ToString() + "\r\n"
            + VT6110_R95.Value.ToString() + "\r\n" + VT6110_R111.Value.ToString() + "\r\n" + VT6110_R127.Value.ToString() + "\r\n" + VT6110_R159.Value.ToString() + "\r\n" + VT6110_R191.Value.ToString() + "\r\n" + VT6110_R223.Value.ToString() + "\r\n" + VT6110_R255.Value.ToString() + "\r\n"

            + VT6110_G0.Value.ToString() + "\r\n" + VT6110_G1.Value.ToString() + "\r\n" + VT6110_G3.Value.ToString() + "\r\n" + VT6110_G5.Value.ToString() + "\r\n" + VT6110_G7.Value.ToString() + "\r\n" + VT6110_G11.Value.ToString() + "\r\n" + VT6110_G15.Value.ToString() + "\r\n" + VT6110_G19.Value.ToString() + "\r\n" + VT6110_G23.Value.ToString() + "\r\n"
            + VT6110_G27.Value.ToString() + "\r\n" + VT6110_G31.Value.ToString() + "\r\n" + VT6110_G35.Value.ToString() + "\r\n" + VT6110_G39.Value.ToString() + "\r\n" + VT6110_G47.Value.ToString() + "\r\n" + VT6110_G55.Value.ToString() + "\r\n" + VT6110_G63.Value.ToString() + "\r\n" + VT6110_G71.Value.ToString() + "\r\n" + VT6110_G79.Value.ToString() + "\r\n"
            + VT6110_G95.Value.ToString() + "\r\n" + VT6110_G111.Value.ToString() + "\r\n" + VT6110_G127.Value.ToString() + "\r\n" + VT6110_G159.Value.ToString() + "\r\n" + VT6110_G191.Value.ToString() + "\r\n" + VT6110_G223.Value.ToString() + "\r\n" + VT6110_G255.Value.ToString() + "\r\n"

            + VT6110_B0.Value.ToString() + "\r\n" + VT6110_B1.Value.ToString() + "\r\n" + VT6110_B3.Value.ToString() + "\r\n" + VT6110_B5.Value.ToString() + "\r\n" + VT6110_B7.Value.ToString() + "\r\n" + VT6110_B11.Value.ToString() + "\r\n" + VT6110_B15.Value.ToString() + "\r\n" + VT6110_B19.Value.ToString() + "\r\n" + VT6110_B23.Value.ToString() + "\r\n"
            + VT6110_B27.Value.ToString() + "\r\n" + VT6110_B31.Value.ToString() + "\r\n" + VT6110_B35.Value.ToString() + "\r\n" + VT6110_B39.Value.ToString() + "\r\n" + VT6110_B47.Value.ToString() + "\r\n" + VT6110_B55.Value.ToString() + "\r\n" + VT6110_B63.Value.ToString() + "\r\n" + VT6110_B71.Value.ToString() + "\r\n" + VT6110_B79.Value.ToString() + "\r\n"
            + VT6110_B95.Value.ToString() + "\r\n" + VT6110_B111.Value.ToString() + "\r\n" + VT6110_B127.Value.ToString() + "\r\n" + VT6110_B159.Value.ToString() + "\r\n" + VT6110_B191.Value.ToString() + "\r\n" + VT6110_B223.Value.ToString() + "\r\n" + VT6110_B255.Value.ToString() + "\r\n";
        }
        private void Button_Save_Gamma_txt_Click(object sender, EventArgs e)
        {
            if (txt_Demura_need_gamma_format.Text == string.Empty)
            {
                MessageBox.Show("内容为空!");
            }
            else
            {
                //创建保存对话框对象
                SaveFileDialog save = new SaveFileDialog();
                save.Filter = "(*.txt)|*.txt"; //过滤文件类型
                save.FilterIndex = 1;
                save.RestoreDirectory = true;
                if (save.ShowDialog() == DialogResult.OK)
                {
                    string path = save.FileName;
                    save.DefaultExt = ".txt";
                    StreamWriter sw = new StreamWriter(path);
                    sw.WriteLine(txt_Demura_need_gamma_format.Text);
                    sw.Close();
                }
            }
        }
    }
}